Skip to content

Commit

Permalink
doc: improved doc
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelint committed Jul 2, 2024
1 parent 04c593d commit 29f27d3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ export async function POST(request: NextRequest) {

## More Examples

- [Expose Anthropic Claude as an OpenAI compatible API](tests/test_functional/fastapi_chat_completion_anthropic/README.md)
- [Use a third party library injector library](tests/test_functional/injector/README.md)

More examples can be found in [`tests/test_functional`](tests/test_functional) directory.
This project is not limited to OpenAI’s models; some examples demonstrate the use of Anthropic’s language models. Anthropic is just one example, and any LangChain-supported vendor is also supported by this library.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Expose as an OpenAI API anthropic assistant
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
app = FastAPI(
title="Langchain Agent OpenAI API Bridge",
version="1.0",
description="OpenAI API exposing langchain agent",
description="OpenAI API exposing langchain agent running on Anthropic Claude",
)

app.add_middleware(
Expand Down
48 changes: 48 additions & 0 deletions tests/test_functional/injector/README.md
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")

```
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
app = FastAPI(
title="Langchain Agent OpenAI API Bridge",
version="1.0",
description="OpenAI API exposing langchain agent",
description="OpenAI API exposing langchain agent using injector",
)

app.add_middleware(
Expand Down

0 comments on commit 29f27d3

Please sign in to comment.