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

Trouble with magentic #12

Open
jaromiru opened this issue May 10, 2024 · 0 comments
Open

Trouble with magentic #12

jaromiru opened this issue May 10, 2024 · 0 comments

Comments

@jaromiru
Copy link

Hi, I tried to use the library along with magentic, but it does not work. I suspect that your OpenAIAPI injection does something it shouldn't.

Minimal example:

from magentic import prompt
import superopenai, traceback

@prompt("Create a list of food ingredients for {meal}.")
def ingredient_list(meal: str) -> list[str]: ...

superopenai.init_superopenai()
try:
    with superopenai.init_logger() as logger:
        res = ingredient_list("chilli con carne")
        print(res)
except:
    traceback.print_exc()

error:

Traceback (most recent call last):
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 503, in complete
    content = next(parse_streamed_tool_calls(response, tool_schemas))
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 267, in parse_streamed_tool_calls
    tool_call = tool_schema.parse_tool_call(chain([first_chunk], tool_call_chunks))
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 220, in parse_tool_call
    return self._function_schema.parse_args(
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/function_schema.py", line 201, in parse_args
    return self._model.model_validate({"value": iter_items}).value
  File "<path>/.venv/lib/python3.10/site-packages/pydantic/main.py", line 551, in model_validate
    return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for Output[list[str]]
value.13
  Error iterating over object, error: KeyError: 'tool_calls' [type=iteration_error, input_value=<generator object Iterabl...expr> at 0x7aa9ac0d63b0>, input_type=generator]
    For further information visit https://errors.pydantic.dev/2.7/v/iteration_error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/tmp/ipykernel_482538/1243833217.py", line 10, in <module>
    res = ingredient_list("chilli con carne")
  File "<path>/.venv/lib/python3.10/site-packages/magentic/prompt_function.py", line 81, in __call__
    message = self.model.complete(
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 510, in complete
    raise StructuredOutputError(msg) from e
magentic.chat_model.base.StructuredOutputError: Failed to parse model output. You may need to update your prompt to encourage the model to return a specific type.

Another error from different project:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "<path>/<project>/__main__.py", line 49, in <module>
    ...
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chatprompt.py", line 88, in __call__
    message = self.model.complete(
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 503, in complete
    content = next(parse_streamed_tool_calls(response, tool_schemas))
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 267, in parse_streamed_tool_calls
    tool_call = tool_schema.parse_tool_call(chain([first_chunk], tool_call_chunks))
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 220, in parse_tool_call
    return self._function_schema.parse_args(
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/function_schema.py", line 300, in parse_args
    args_json = "".join(chunks)
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 220, in <genexpr>
    return self._function_schema.parse_args(
  File "<path>/.venv/lib/python3.10/site-packages/magentic/chat_model/openai_chat_model.py", line 247, in <genexpr>
    all_tool_call_chunks = (
  File "<path>/.venv/lib/python3.10/site-packages/superopenai/wrap_openai.py", line 28, in gen
    logger.log(StreamingChatCompletionLog.create(
  File "<path>/.venv/lib/python3.10/site-packages/superopenai/state.py", line 31, in log
    self.filestream.write(str(log) + "\n")
  File "<path>/.venv/lib/python3.10/site-packages/superopenai/types.py", line 285, in __str__
    if msg['tool_calls']:
KeyError: 'tool_calls'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant