Skip to content

Commit

Permalink
Azure test for ChatOpenAI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brainlid committed Dec 15, 2024
1 parent 38e17e0 commit 039ae65
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion .envrc_template
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ export OPENAI_ORG_ID="YOUR_OPENAI_ORG_ID"
export ANTHROPIC_API_KEY="YOUR_ANTHROPIC_API_KEY"
export GOOGLE_API_KEY="YOUR_GOOGLE_API_KEY"
export AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"
export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"
export AZURE_OPENAI_ENDPOINT="YOUR_AZURE_MODEL_ENDPOINT"
export AZURE_OPENAI_KEY="YOUR_AZURE_ENDPOINT_KEY"
31 changes: 31 additions & 0 deletions test/chat_models/chat_open_ai_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,36 @@ defmodule LangChain.ChatModels.ChatOpenAITest do
assert reason.type == nil
assert reason.message =~ "maximum context length"
end

@tag live_call: true, live_azure: true
test "supports Azure hosted OpenAI models" do
# https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cjavascript-keyless%2Ctypescript-keyless%2Cpython-new&pivots=rest-api

endpoint = System.fetch_env!("AZURE_OPENAI_ENDPOINT")
api_key = System.fetch_env!("AZURE_OPENAI_KEY")

{:ok, chat} =
ChatOpenAI.new(%{
endpoint: endpoint,
api_key: api_key,
seed: 0,
temperature: 1,
stream: false
})

{:ok, [message]} =
ChatOpenAI.call(
chat,
[
Message.new_user!("Return the response 'Hi'.")
],
[]
)

assert message.content =~ "Hi"
assert message.role == :assistant
assert message.index == 0
end
end

describe "do_process_response/2" do
Expand Down Expand Up @@ -1291,6 +1321,7 @@ defmodule LangChain.ChatModels.ChatOpenAITest do
{:error, %LangChainError{} = reason} = ChatOpenAI.call(chat, [], [])

assert reason.type == nil

assert reason.message ==
"Invalid 'messages': empty array. Expected an array with minimum length 1, but got an empty array instead."
end
Expand Down

0 comments on commit 039ae65

Please sign in to comment.