Skip to content

Commit

Permalink
strip not given kwargs for openai (#154)
Browse files Browse the repository at this point in the history
* strip not given kwargs for openai

* add more tests
  • Loading branch information
wenzhe-log10 committed Apr 25, 2024
1 parent 2de7396 commit 209cf6c
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ logging-tags:
python examples/logging/tags_openai.py

logging-magentic:
python examples/logging/magentic_async_stream_logging.py
python examples/logging/magentic_prompt.py
python examples/logging/magentic_prompt_stream.py
python examples/logging/magentic_function_logging.py
python examples/logging/magentic_async_stream_logging.py
python examples/logging/magentic_async_parallel_function_call.py
python examples/logging/magentic_async_multi_session_tags.py
python examples/logging/magentic_async_widget.py
Expand Down
14 changes: 14 additions & 0 deletions examples/logging/magentic_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import openai
from magentic import prompt

from log10.load import log10


log10(openai, USE_ASYNC_=True)


@prompt("Tell me a joke")
def llm() -> str: ...


print(llm())
16 changes: 16 additions & 0 deletions examples/logging/magentic_prompt_stream.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import openai
from magentic import StreamedStr, prompt

from log10.load import log10


log10(openai, USE_ASYNC_=True)


@prompt("Tell me a joke")
def llm() -> StreamedStr: ...


response = llm()
for chunk in response:
print(chunk, end="", flush=True)
20 changes: 20 additions & 0 deletions examples/logging/openai_chat_not_given.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from openai import NOT_GIVEN

from log10.load import OpenAI


client = OpenAI()

completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": "tell a joke.",
},
],
tools=NOT_GIVEN,
tool_choice=NOT_GIVEN,
)

print(completion.choices[0].message.content)
3 changes: 3 additions & 0 deletions log10/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,9 @@ def _init_log_row(func, *args, **kwargs):
elif "mistralai" in func.__module__:
log_row["kind"] = "chat"
elif "openai" in func.__module__:
from openai._utils._utils import strip_not_given

kwargs_copy = strip_not_given(kwargs_copy)
kind = "chat" if "chat" in func.__module__ else "completion"
log_row["kind"] = kind
elif "google.generativeai" in func.__module__:
Expand Down

0 comments on commit 209cf6c

Please sign in to comment.