Skip to content

Commit 6652375

Browse files
authored
Merge pull request #332 from Scale3-Labs/obinna/S3EN-2718-fix-azure-openai
Obinna/s3 en 2718 fix azure openai
2 parents 85eef8c + a22642e commit 6652375

File tree

5 files changed

+41
-3
lines changed

5 files changed

+41
-3
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/langtrace_python_sdk/utils/llm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def get_llm_request_attributes(kwargs, prompts=None, model=None, operation_name=
126126
tools = kwargs.get("tools", None)
127127
return {
128128
SpanAttributes.LLM_OPERATION_NAME: operation_name,
129-
SpanAttributes.LLM_REQUEST_MODEL: model or kwargs.get("model"),
129+
SpanAttributes.LLM_REQUEST_MODEL: model or kwargs.get("model") or "gpt-3.5-turbo",
130130
SpanAttributes.LLM_IS_STREAMING: kwargs.get("stream"),
131131
SpanAttributes.LLM_REQUEST_TEMPERATURE: kwargs.get("temperature"),
132132
SpanAttributes.LLM_TOP_K: top_k,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "2.3.5"
1+
__version__ = "2.3.6"

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": True,
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)