Antoine101 commited on
Commit
f11b0ca
·
verified ·
1 Parent(s): 1a32495

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -9
app.py CHANGED
@@ -15,6 +15,17 @@ from langchain_groq import ChatGroq
15
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
16
  from langchain_huggingface.llms import HuggingFacePipeline
17
  from langchain_ollama import ChatOllama
 
 
 
 
 
 
 
 
 
 
 
18
 
19
 
20
  # (Keep Constants as is)
@@ -36,9 +47,9 @@ HF_TOKEN = os.getenv("HF_TOKEN")
36
  # provider='auto'
37
  #)
38
 
39
- checkpoint = "meta-llama/Llama-3.2-3B-Instruct"
40
- tokenizer = AutoTokenizer.from_pretrained(checkpoint)
41
- model = AutoModelForCausalLM.from_pretrained(checkpoint, token=HF_TOKEN)
42
 
43
  #messages = [{"role": "user", "content": "Hello."}]
44
  #input_text=tokenizer.apply_chat_template(messages, tokenize=False)
@@ -47,14 +58,25 @@ model = AutoModelForCausalLM.from_pretrained(checkpoint, token=HF_TOKEN)
47
  #outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
48
  #print(tokenizer.decode(outputs[0]))
49
 
50
- pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, max_new_tokens=1000)
51
- hf_pipe = HuggingFacePipeline(pipeline=pipe)
52
 
53
  #chat = ChatHuggingFace(llm=llm, verbose=True)
54
- chat = ChatOllama(llm=hf_pipe).bind(skip_prompt=True)
55
 
56
- tools = []
57
- chat_with_tools = chat.bind_tools(tools)
 
 
 
 
 
 
 
 
 
 
 
58
 
59
  # load the system prompt from the file
60
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
@@ -113,7 +135,17 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
113
 
114
  # 1. Instantiate Agent ( modify this part to create your agent)
115
  try:
116
- agent = BasicAgent()
 
 
 
 
 
 
 
 
 
 
117
  except Exception as e:
118
  print(f"Error instantiating agent: {e}")
119
  return f"Error initializing agent: {e}", None
 
15
  from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
16
  from langchain_huggingface.llms import HuggingFacePipeline
17
  from langchain_ollama import ChatOllama
18
+ from smolagents import (
19
+ InferenceClientModel, LiteLLMModel, OpenAIServerModel, TransformersModel,
20
+ CodeAgent,
21
+ DuckDuckGoSearchTool,
22
+ HfApiModel,
23
+ LiteLLMModel,
24
+ OpenAIServerModel,
25
+ PythonInterpreterTool,
26
+ tool,
27
+ InferenceClientModel, ToolCallingAgent
28
+ )
29
 
30
 
31
  # (Keep Constants as is)
 
47
  # provider='auto'
48
  #)
49
 
50
+ #checkpoint = "meta-llama/Llama-3.2-3B-Instruct"
51
+ #tokenizer = AutoTokenizer.from_pretrained(checkpoint)
52
+ #model = AutoModelForCausalLM.from_pretrained(checkpoint, token=HF_TOKEN)
53
 
54
  #messages = [{"role": "user", "content": "Hello."}]
55
  #input_text=tokenizer.apply_chat_template(messages, tokenize=False)
 
58
  #outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
59
  #print(tokenizer.decode(outputs[0]))
60
 
61
+ #pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, max_new_tokens=1000)
62
+ #hf_pipe = HuggingFacePipeline(pipeline=pipe)
63
 
64
  #chat = ChatHuggingFace(llm=llm, verbose=True)
65
+ #chat = ChatOllama(llm=hf_pipe).bind(skip_prompt=True)
66
 
67
+ #tools = []
68
+ #chat_with_tools = chat.bind_tools(tools)
69
+
70
+ openai_api_key = os.getenv("OPENAI_API_KEY")
71
+
72
+ model = OpenAIServerModel(
73
+ api_key=openai_api_key,
74
+ model_id="o1"
75
+ )
76
+ tools = [
77
+ DuckDuckGoSearchTool(),
78
+ PythonInterpreterTool(),
79
+ ]
80
 
81
  # load the system prompt from the file
82
  with open("system_prompt.txt", "r", encoding="utf-8") as f:
 
135
 
136
  # 1. Instantiate Agent ( modify this part to create your agent)
137
  try:
138
+ #agent = BasicAgent()
139
+ agent = CodeAgent(
140
+ tools=tools,
141
+ model=model,
142
+ additional_authorized_imports=["*"],
143
+ executor_type='local',
144
+ executor_kwargs={},
145
+ max_steps=12,
146
+ verbosity_level=2,
147
+ planning_interval=4,
148
+ )
149
  except Exception as e:
150
  print(f"Error instantiating agent: {e}")
151
  return f"Error initializing agent: {e}", None