Spaces:
Sleeping
Sleeping
Commit ·
7903382
1
Parent(s): e77d681
second draft
Browse files
.env
ADDED
|
File without changes
|
agent.py
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import CodeAgent, InferenceClientModel, ToolCallingAgent, DuckDuckGoSearchTool
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
import os
|
| 4 |
+
load_dotenv()
|
| 5 |
+
model_id = "meta-llama/Llama-3.3-70B-Instruct"
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def basic_inference(
|
| 9 |
+
prompt: str,
|
| 10 |
+
model_id: str = "meta-llama/Llama-3.3-70B-Instruct",
|
| 11 |
+
provider: str = "groq",
|
| 12 |
+
):
|
| 13 |
+
"""
|
| 14 |
+
Run a basic inference using the specified model and provider.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
prompt (str): The input prompt for the model.
|
| 18 |
+
model_id (str): The ID of the model to use.
|
| 19 |
+
provider (str): The provider to use for inference.
|
| 20 |
+
|
| 21 |
+
Returns:
|
| 22 |
+
str: The model's response.
|
| 23 |
+
"""
|
| 24 |
+
# Load the model
|
| 25 |
+
model = InferenceClientModel(model_id=model_id, token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")) # You can choose to not pass any model_id to InferenceClientModel to use a default model
|
| 26 |
+
# you can also specify a particular provider e.g. provider="together" or provider="sambanova"
|
| 27 |
+
|
| 28 |
+
# Create an agent with the specified tools and model
|
| 29 |
+
agent = CodeAgent(tools=[], model=model, add_base_tools=True)
|
| 30 |
+
|
| 31 |
+
# Run the agent with the provided prompt
|
| 32 |
+
return agent.run(prompt)
|
| 33 |
+
|
| 34 |
+
def toolcalling(
|
| 35 |
+
prompt: str,
|
| 36 |
+
model_id: str = "meta-llama/Llama-3.3-70B-Instruct",
|
| 37 |
+
provider: str = "groq",
|
| 38 |
+
):
|
| 39 |
+
"""
|
| 40 |
+
Run a tool calling inference using the specified model and provider.
|
| 41 |
+
|
| 42 |
+
Args:
|
| 43 |
+
prompt (str): The input prompt for the model.
|
| 44 |
+
model_id (str): The ID of the model to use.
|
| 45 |
+
provider (str): The provider to use for inference.
|
| 46 |
+
|
| 47 |
+
Returns:
|
| 48 |
+
str: The model's response.
|
| 49 |
+
"""
|
| 50 |
+
# Load the model
|
| 51 |
+
model = InferenceClientModel(model_id=model_id, token=os.environ.get("HUGGINGFACEHUB_API_TOKEN")) # You can choose to not pass any model_id to InferenceClientModel to use a default model
|
| 52 |
+
# you can also specify a particular provider e.g. provider="together" or provider="sambanova"
|
| 53 |
+
|
| 54 |
+
# Create an agent with the specified tools and model
|
| 55 |
+
agent = ToolCallingAgent(tools=[], model=model, add_base_tools=True)
|
| 56 |
+
|
| 57 |
+
# Run the agent with the provided prompt
|
| 58 |
+
return agent.run(prompt)
|
| 59 |
+
|
| 60 |
+
def web_search(query: str) -> str:
|
| 61 |
+
"""Search DuckDuckGo for a query and return maximum 3 result.
|
| 62 |
+
|
| 63 |
+
Args:
|
| 64 |
+
query: The search query."""
|
| 65 |
+
search_tool = DuckDuckGoSearchTool()
|
| 66 |
+
search_docs = search_tool(query)
|
| 67 |
+
return search_docs
|