Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Minor updates #131

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions .github/workflows/docs.yml

This file was deleted.

84 changes: 84 additions & 0 deletions Examples/tool_calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
from openai import OpenAI
from rich import print
from sparrow import MeasureTime, yaml_load # pip install sparrow-python

config = yaml_load("config.yaml", rel_path=True)
print(f"{config=}")

client = OpenAI(
api_key=config['api_key'],
base_url=config['api_base'],
)
stream = True

n = 1

# debug = True
debug = False

caching = True

max_tokens = None

model = "gpt-3.5-turbo"
# model="gpt-4"

mt = MeasureTime().start()
tools = [
{
"type": "function",
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
},
"required": ["location"],
},
},
}
]
resp = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": "What's the weather like in Boston today?"}],
tools=tools,
tool_choice="auto", # auto is default, but we'll be explicit
stream=stream,
extra_body={"caching": caching},
)

if stream:
if debug:
for chunk in resp:
print(chunk)
else:
for idx, chunk in enumerate(resp):
chunk_message = chunk.choices[0].delta or ""
if idx == 0:
mt.show_interval("tcp time:")
function = chunk_message.tool_calls[0].function
name = function.name
print(f"{chunk_message.role}: \n{name}: ")
continue

content = ""
tool_calls = chunk_message.tool_calls
if tool_calls:
function = tool_calls[0].function
if function:
content = function.arguments or ""
print(content, end="")
print()
else:
print(resp)
assistant_content = resp.choices[0].message.content
print(assistant_content)
print(resp.usage)

mt.show_interval("tool_calls")
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**简体中文** | [**English**](https://github.com/KenyonY/openai-forward/blob/main/README_EN.md)

<h1 align="center">
<a href="https://github.com/KenyonY/openai-forward"> 🌠 OpenAI Forward </a>
<a href="https://github.com/KenyonY/openai-forward"> OpenAI Forward </a>
<br>
<br>
</h1>
Expand All @@ -26,8 +26,6 @@

<div align="center">

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/KenyonY/openai-forward)

[特点](#主要特性) |
[部署指南](deploy.md) |
[使用指南](#使用指南) |
Expand Down
4 changes: 1 addition & 3 deletions README_EN.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
**English** | [**简体中文**](https://github.com/KenyonY/openai-forward/blob/main/README.md)

<h1 align="center">
<a href="https://github.com/KenyonY/openai-forward"> 🌠 OpenAI Forward </a>
<a href="https://github.com/KenyonY/openai-forward"> OpenAI Forward </a>
<br>
<br>
</h1>
Expand All @@ -27,8 +27,6 @@

<div align="center">

[![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/KenyonY/openai-forward)


[Features](#Key-Features) |
[Deployment Guide](deploy_en.md) |
Expand Down
Loading