mjsolidarios commited on
Commit
5e521fb
·
1 Parent(s): b6e9db6

Full commit.

Browse files
Files changed (2) hide show
  1. app.py +77 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import InferenceClient
3
+ import gradio as gr
4
+
5
+ token = os.environ["HF_TOKEN"]
6
+
7
+ client = InferenceClient("meta-llama/Llama-3.2-3B-Instruct", token=token)
8
+
9
+ SYSTEM_PROMPT = """Answer the following questions as best you can. You have access to the following tools:
10
+
11
+ get_weather: Get the current weather in a given location
12
+
13
+ The way you use the tools is by specifying a json blob.
14
+ Specifically, this json should have a `action` key (with the name of the tool to use) and a `action_input` key (with the input to the tool going here).
15
+
16
+ The only values that should be in the "action" field are:
17
+ get_weather: Get the current weather in a given location, args: {"location": {"type": "string"}}
18
+ example use :
19
+ ```
20
+ {{
21
+ "action": "get_weather",
22
+ "action_input": {"location": "New York"}
23
+ }}
24
+
25
+ ALWAYS use the following format:
26
+
27
+ Question: the input question you must answer
28
+ Thought: you should always think about one action to take. Only one action at a time in this format:
29
+ Action:
30
+ ```
31
+ $JSON_BLOB
32
+ ```
33
+ Observation: the result of the action. This Observation is unique, complete, and the source of truth.
34
+ ... (this Thought/Action/Observation can repeat N times, you should take several steps when needed. The $JSON_BLOB must be formatted as markdown and only use a SINGLE action at a time.)
35
+
36
+ You must always end your output with the following format:
37
+
38
+ Thought: I now know the final answer
39
+ Final Answer: the final answer to the original input question
40
+
41
+ Now begin! Reminder to ALWAYS use the exact characters `Final Answer:` when you provide a definitive answer. """
42
+
43
+ prompt=f"""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
44
+ {SYSTEM_PROMPT}
45
+ <|eot_id|><|start_header_id|>user<|end_header_id|>
46
+ What's the weather in London ?
47
+ <|eot_id|><|start_header_id|>assistant<|end_header_id|>
48
+ """
49
+
50
+ output = client.text_generation(
51
+ prompt,
52
+ max_new_tokens=200,
53
+ stop=["Observation:"]
54
+ )
55
+
56
+ # Dummy function
57
+ def get_weather(location):
58
+ return f"the weather in {location} is sunny with low temperatures. \n"
59
+
60
+ new_prompt=prompt+output+get_weather('London')
61
+
62
+ final_output = client.text_generation(
63
+ new_prompt,
64
+ max_new_tokens=200,
65
+ )
66
+
67
+ def llm():
68
+ return final_output
69
+
70
+ app = gr.Interface(
71
+ title="Simple Agent",
72
+ description="A simple agent that completes the text.",
73
+ fn=llm,
74
+ inputs=None,
75
+ outputs="text"
76
+ )
77
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ huggingface_hub