Skip to content

Commit e010e86

Browse files
committed
add auzre openai example
1 parent 0938590 commit e010e86

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from examples.azureopenai_example.completion import chat_completion
2+
from langtrace_python_sdk import with_langtrace_root_span, langtrace
3+
4+
langtrace.init()
5+
6+
class AzureOpenAIRunner:
7+
@with_langtrace_root_span("AzureOpenAI")
8+
def run(self):
9+
chat_completion()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
from langchain_openai import AzureChatOpenAI
3+
4+
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
5+
6+
model = AzureChatOpenAI(
7+
azure_endpoint=os.environ['AZURE_OPENAI_ENDPOINT'],
8+
azure_deployment=os.environ['AZURE_OPENAI_DEPLOYMENT_NAME'],
9+
openai_api_version=os.environ['AZURE_OPENAI_API_VERSION'],
10+
)
11+
12+
@with_langtrace_root_span()
13+
def chat_completion():
14+
messages = [
15+
(
16+
"system",
17+
"You are a helpful assistant that translates English to French. Translate the user sentence.",
18+
),
19+
("human", "I love programming."),
20+
]
21+
result = model.invoke(messages)
22+
print(result)

src/run_example.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
ENABLED_EXAMPLES = {
44
"anthropic": False,
5+
"azureopenai": True,
56
"chroma": False,
67
"cohere": False,
78
"fastapi": False,
89
"langchain": False,
910
"llamaindex": False,
1011
"hiveagent": False,
11-
"openai": True,
12+
"openai": False,
1213
"perplexity": False,
1314
"pinecone": False,
1415
"qdrant": False,
@@ -110,3 +111,9 @@
110111

111112
print(Fore.BLUE + "Running Mistral example" + Fore.RESET)
112113
MistralRunner().run()
114+
115+
if ENABLED_EXAMPLES["azureopenai"]:
116+
from examples.azureopenai_example import AzureOpenAIRunner
117+
118+
print(Fore.BLUE + "Running Azure OpenAI example" + Fore.RESET)
119+
AzureOpenAIRunner().run()

0 commit comments

Comments
 (0)