-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tests/test_functional/fastapi_chat_completion_anthropic/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Expose as an OpenAI API anthropic assistant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# With Injector Example | ||
|
||
Usage example using a third party injector library. | ||
`poetry add injector` https://github.com/python-injector/injector for this example | ||
|
||
```python | ||
from fastapi import FastAPI | ||
from dotenv import load_dotenv, find_dotenv | ||
import uvicorn | ||
from injector import Injector | ||
|
||
from langchain_openai_api_bridge.assistant import ( | ||
ThreadRepository, | ||
MessageRepository, | ||
RunRepository, | ||
) | ||
from langchain_openai_api_bridge.core.agent_factory import AgentFactory | ||
from langchain_openai_api_bridge.fastapi import ( | ||
LangchainOpenaiApiBridgeFastAPI, | ||
) | ||
from tests.test_functional.injector.app_module import MyAppModule | ||
|
||
|
||
_ = load_dotenv(find_dotenv()) | ||
|
||
|
||
app = FastAPI( | ||
title="Langchain Agent OpenAI API Bridge", | ||
version="1.0", | ||
description="OpenAI API exposing langchain agent using injector", | ||
) | ||
|
||
injector = Injector([MyAppModule()]) | ||
|
||
bridge = LangchainOpenaiApiBridgeFastAPI( | ||
app=app, agent_factory_provider=lambda: injector.get(AgentFactory) | ||
) | ||
bridge.bind_openai_assistant_api( | ||
thread_repository_provider=lambda: injector.get(ThreadRepository), | ||
message_repository_provider=lambda: injector.get(MessageRepository), | ||
run_repository_provider=lambda: injector.get(RunRepository), | ||
prefix="/my-assistant", | ||
) | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="localhost") | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters