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

Is there a way to support OpenAI's File Search, Assistants, and Runs? #315

Open
CiANSfi opened this issue Aug 20, 2024 · 2 comments
Open

Comments

@CiANSfi
Copy link

CiANSfi commented Aug 20, 2024

File Search, Assistants, and Runs: https://platform.openai.com/docs/assistants/tools/file-search?context=without-streaming

OpenAI has a vector db and allows for Assistants to search and retrieve from them. Their API allows you to use this OpenAI tool along with your own custom tools via function calling. I'm wondering if Magentic can already wrap around the File Search and Assistants APIs, if not explicitly out-the-box then perhaps in a hacky way for now (eg. is the only option to write the wrapper myself in a custom function and then use FunctionCall() on it?).

@jackmpcollins
Copy link
Owner

jackmpcollins commented Aug 21, 2024

@CiANSfi I haven't used the OpenAI Assistants API yet or put much thought into how magentic might use it. If there's a specific place you think magentic could help I'd be interested to hear.

For converting functions to JSON schema and parsing the LLM output back into a FunctionCall check out FunctionCallFunctionSchema in magentic. The other FunctionSchema classes are for python classes and might also be of interest. Here's how OpenaiChatModel uses these to convert types and functions for the chat completion call.

if output_types is None:
output_types = [] if functions else cast(list[type[R]], [str])
# TODO: Check that Function calls types match functions
function_schemas = [FunctionCallFunctionSchema(f) for f in functions or []] + [
function_schema_for_type(type_)
for type_ in output_types
if not is_origin_subclass(type_, STR_OR_FUNCTIONCALL_TYPE)
]
tool_schemas = [FunctionToolSchema(schema) for schema in function_schemas]

@CiANSfi
Copy link
Author

CiANSfi commented Aug 23, 2024

@jackmpcollins The Assistants API (and accompanying Vector Database API) are not great, or maybe it's just that their documentation is lacking, or a little of both. The users over at the OpenAI community forum seem to agree.

I'll look into this class a bit more when I have the time and then I'll see if I can whip up something on my own. Actually I just realized I failed to mention that both APIs are under beta so I'm not sure if that changes how you would approach things (from a feature prioritization point of view).

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

2 participants