susmitsil commited on
Commit
c68b100
·
verified ·
1 Parent(s): a2a3ee4
Files changed (1) hide show
  1. app.py +50 -10
app.py CHANGED
@@ -6,13 +6,48 @@ import pandas as pd
6
 
7
  from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, LiteLLMModel
8
  from langchain_openai import AzureChatOpenAI
 
9
 
10
  # (Keep Constants as is)
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  # --- Basic Agent Definition ---
18
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
@@ -45,17 +80,22 @@ class BasicAgent:
45
  # Be cautious printing the key, maybe just check if it exists
46
  print(f"AZURE_OPENAI_KEY set: {'AZURE_OPENAI_KEY' in os.environ}")
47
 
48
- model = AzureChatOpenAI(
49
- azure_endpoint=os.getenv("AZURE_API_ENDPOINT"),
50
- azure_deployment=os.getenv("AZURE_DEPLOYMENT_NME"), # or your deployment
51
- api_key=os.getenv("AZURE_OPENAI_KEY"),
52
- api_version=os.getenv("AZURE_API_VERSION"),
53
- temperature=0.5,
54
- max_tokens=None,
55
- timeout=None,
56
- max_retries=2,
 
 
 
 
 
 
57
  )
58
-
59
  # Initialize the search tool
60
  search_tool = DuckDuckGoSearchTool()
61
  print("DuckDuckSearchTool instantiated")
 
6
 
7
  from smolagents import CodeAgent, DuckDuckGoSearchTool, OpenAIServerModel, LiteLLMModel
8
  from langchain_openai import AzureChatOpenAI
9
+ from typing import Optional, Dict
10
 
11
  # (Keep Constants as is)
12
  # --- Constants ---
13
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
14
 
15
 
16
+ class AzureOpenAIServerModel(OpenAIServerModel):
17
+ """This model connects to an Azure OpenAI deployment.
18
+
19
+ Parameters:
20
+ model_id (`str`):
21
+ The model identifier to use on the server (e.g. "gpt-3.5-turbo").
22
+ azure_endpoint (`str`, *optional*):
23
+ The Azure endpoint, including the resource, e.g. `https://example-resource.azure.openai.com/`
24
+ api_key (`str`, *optional*):
25
+ The API key to use for authentication.
26
+ custom_role_conversions (`Dict{str, str]`, *optional*):
27
+ Custom role conversion mapping to convert message roles in others.
28
+ Useful for specific models that do not support specific message roles like "system".
29
+ **kwargs:
30
+ Additional keyword arguments to pass to the Azure OpenAI API.
31
+ """
32
 
33
+ def __init__(
34
+ self,
35
+ model_id: str,
36
+ azure_endpoint: Optional[str] = None,
37
+ api_key: Optional[str] = None,
38
+ api_version: Optional[str] = None,
39
+ custom_role_conversions: Optional[Dict[str, str]] = None,
40
+ **kwargs,
41
+ ):
42
+ super().__init__(model_id=model_id, api_key=api_key, custom_role_conversions=custom_role_conversions, **kwargs)
43
+ # if we've reached this point, it means the openai package is available (baseclass check) so go ahead and import it
44
+ import openai
45
+
46
+ self.client = openai.AzureOpenAI(
47
+ api_key=api_key,
48
+ api_version=api_version,
49
+ azure_endpoint=azure_endpoint
50
+ )
51
 
52
  # --- Basic Agent Definition ---
53
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
80
  # Be cautious printing the key, maybe just check if it exists
81
  print(f"AZURE_OPENAI_KEY set: {'AZURE_OPENAI_KEY' in os.environ}")
82
 
83
+ # model = AzureChatOpenAI(
84
+ # azure_endpoint=os.getenv("AZURE_API_ENDPOINT"),
85
+ # azure_deployment=os.getenv("AZURE_DEPLOYMENT_NME"), # or your deployment
86
+ # api_key=os.getenv("AZURE_OPENAI_KEY"),
87
+ # api_version=os.getenv("AZURE_API_VERSION"),
88
+ # temperature=0.5,
89
+ # max_tokens=None,
90
+ # timeout=None,
91
+ # max_retries=2,
92
+ # )
93
+ model = AzureOpenAIServerModel(
94
+ model_id = os.environ.get("AZURE_DEPLOYMENT_NME"),
95
+ api_key=os.environ.get("AZURE_OPENAI_KEY"),
96
+ api_version=os.environ.get("AZURE_API_VERSION"),
97
+ azure_endpoint=os.environ.get("AZURE_API_ENDPOINT")
98
  )
 
99
  # Initialize the search tool
100
  search_tool = DuckDuckGoSearchTool()
101
  print("DuckDuckSearchTool instantiated")