Skip to content

Commit

Permalink
chore(examples): add langchain-openai example from #58
Browse files Browse the repository at this point in the history
  • Loading branch information
mharrisb1 committed Aug 12, 2024
1 parent 1d6be48 commit c5f3d3d
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions examples/test_langchain_openai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from langchain_openai import ChatOpenAI
from pydantic.v1 import SecretStr

import openai_responses
from openai_responses import OpenAIMock


@openai_responses.mock()
def test_langchain_chat_openai_invoke(openai_mock: OpenAIMock):
openai_mock.chat.completions.create.response = {
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"content": "J'adore la programmation.",
"role": "assistant",
},
}
]
}

llm = ChatOpenAI(
name="My Custom Chatbot",
model="gpt-4o",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
api_key=SecretStr("sk-fake123"),
)

messages = [
(
"system",
"You are a helpful assistant that translates English to French. Translate the user sentence.",
),
("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
assert ai_msg.content == "J'adore la programmation." # type: ignore

0 comments on commit c5f3d3d

Please sign in to comment.