jpfearnworks commited on
Commit
800b349
1 Parent(s): 6396658

Add api_key inputs

Browse files
README.MD DELETED
@@ -1,61 +0,0 @@
1
- ---
2
- title: Ai Agents
3
- emoji: 📊
4
- colorFrom: green
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 3.35.2
8
- app_file: server.py
9
- pinned: false
10
- license: apache-2.0
11
- ---
12
-
13
- # AI Agents
14
- A collection of patterns for experimenting with agents, llm pipelines, and ChainOfThoughtStrategy.
15
- Heavily inspired by examples and code across the AI Open Source community but with some fearnworks patterns heavily interspersed.
16
-
17
- ## UI
18
- Front end for templates currently uses streamlit, however display for each agent example will be heavily decoupled from deployment avenue.
19
- Strategies for jupyter, gradio, and react will be prioritized in general at this time.
20
-
21
- ## Modules
22
-
23
- ### Reasoning
24
-
25
- General problem solving requiring reasoned processing. Utilizing tree of thoughts, chain of thought, and reAct. Current prompts heavily inspired by
26
- work from https://github.com/mrspiggot
27
-
28
- ### Knowledge Domains
29
-
30
- Example of knowledge domain retrieval. Given a question the router determines the best knowledge domain chain to use and then calls that chain to handle the response.
31
-
32
- Includes examples of queries that will return each of the four implemented domains.
33
-
34
- ### Generative Image Prompting Patterns
35
-
36
- Coming soon
37
-
38
- ### Generative Simulacra Pattern
39
-
40
- Coming soon
41
-
42
- ### Story Telling / Dungeon Master Patterns
43
-
44
- Coming Soon
45
-
46
- ### Deployment
47
-
48
- Project is packaged with a dockerfile expose a gradio ui on localhost:7000. Please use the envtemplate file to create your .env for running the project
49
-
50
- To build & run
51
-
52
- ```
53
- docker build . -t ai_agent:latest
54
- docker run -it -p 7000:7000 ai_agent:latest
55
- ```
56
-
57
- To build, run, and, clean up image in one command :
58
-
59
- ```
60
- docker build . -t ai_agent:latest && docker run --rm -it -p 7000:7000 --name ai_agent_container ai_agent:latest
61
- ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -7,4 +7,56 @@ colorFrom: green
7
  colorTo: red
8
  pinned: true
9
  app_file: server.py
10
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  colorTo: red
8
  pinned: true
9
  app_file: server.py
10
+ app_port: 7000
11
+ ---
12
+
13
+
14
+ # AI Agents
15
+ A collection of patterns for experimenting with agents, llm pipelines, and ChainOfThoughtStrategy.
16
+ Heavily inspired by examples and code across the AI Open Source community but with some fearnworks patterns heavily interspersed.
17
+
18
+ ## UI
19
+ Front end for templates currently uses streamlit, however display for each agent example will be heavily decoupled from deployment avenue.
20
+ Strategies for jupyter, gradio, and react will be prioritized in general at this time.
21
+
22
+ ## Modules
23
+
24
+ ### Reasoning
25
+
26
+ General problem solving requiring reasoned processing. Utilizing tree of thoughts, chain of thought, and reAct. Current prompts heavily inspired by
27
+ work from https://github.com/mrspiggot
28
+
29
+ ### Knowledge Domains
30
+
31
+ Example of knowledge domain retrieval. Given a question the router determines the best knowledge domain chain to use and then calls that chain to handle the response.
32
+
33
+ Includes examples of queries that will return each of the four implemented domains.
34
+
35
+ ### Generative Image Prompting Patterns
36
+
37
+ Coming soon
38
+
39
+ ### Generative Simulacra Pattern
40
+
41
+ Coming soon
42
+
43
+ ### Story Telling / Dungeon Master Patterns
44
+
45
+ Coming Soon
46
+
47
+ ### Deployment
48
+
49
+ Project is packaged with a dockerfile expose a gradio ui on localhost:7000. Please use the envtemplate file to create your .env for running the project
50
+
51
+ To build & run
52
+
53
+ ```
54
+ docker build . -t ai_agent:latest
55
+ docker run -it -p 7000:7000 ai_agent:latest
56
+ ```
57
+
58
+ To build, run, and, clean up image in one command :
59
+
60
+ ```
61
+ docker build . -t ai_agent:latest && docker run --rm -it -p 7000:7000 --name ai_agent_container ai_agent:latest
62
+ ```
modules/knowledge_retrieval/component.py CHANGED
@@ -3,16 +3,17 @@ import gradio as gr
3
  import os
4
  openai_api_key = os.getenv("OPENAI_API_KEY")
5
 
6
- def determine_and_execute(question: str, temperature: float):
7
  config = get_knowledge_domain_router_config(temperature=temperature)
8
  config.temperature = temperature
9
- determiner = KnowledgeDomainRouter(api_key=openai_api_key, config=config, question=question, display=print)
10
  determine_output, execute_output = determiner.determine_and_execute(question=question)
11
  return determine_output, execute_output
12
 
13
  examples = [["""When is my grandmothers birthday?""", 0.6], ["What was my tax burden last year?", 0.6 ], ["What is the most recent magic the gathering card set released?", 0.6], ["What products are the most popular with my small business customers?", 0.6]]
14
 
15
  def create_knowledge_router_ui(cache_examples=False):
 
16
  with gr.Row():
17
  question = gr.Textbox(label="Enter your question here:")
18
  temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
@@ -21,6 +22,6 @@ def create_knowledge_router_ui(cache_examples=False):
21
  reasoning = gr.Textbox(label="Reasoning")
22
 
23
  generate_button = gr.Button(label="Generate")
24
- generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature])
25
  gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
26
 
 
3
  import os
4
  openai_api_key = os.getenv("OPENAI_API_KEY")
5
 
6
+ def determine_and_execute(api_key, question: str, temperature: float):
7
  config = get_knowledge_domain_router_config(temperature=temperature)
8
  config.temperature = temperature
9
+ determiner = KnowledgeDomainRouter(api_key=api_key, config=config, question=question, display=print)
10
  determine_output, execute_output = determiner.determine_and_execute(question=question)
11
  return determine_output, execute_output
12
 
13
  examples = [["""When is my grandmothers birthday?""", 0.6], ["What was my tax burden last year?", 0.6 ], ["What is the most recent magic the gathering card set released?", 0.6], ["What products are the most popular with my small business customers?", 0.6]]
14
 
15
  def create_knowledge_router_ui(cache_examples=False):
16
+ api_key = gr.Textbox(label="You OpenAI API key", type="password")
17
  with gr.Row():
18
  question = gr.Textbox(label="Enter your question here:")
19
  temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
 
22
  reasoning = gr.Textbox(label="Reasoning")
23
 
24
  generate_button = gr.Button(label="Generate")
25
+ generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[api_key, question, temperature])
26
  gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
27
 
modules/reasoning/component.py CHANGED
@@ -4,10 +4,10 @@ import os
4
  openai_api_key = os.getenv("OPENAI_API_KEY")
5
 
6
 
7
- def determine_and_execute(question, temperature):
8
  config = get_reasoning_router_config(temperature=temperature)
9
  config.temperature = temperature
10
- determiner = ReasoningRouter(api_key=openai_api_key, config=config, question=question, display=print)
11
  determine_output, execute_output = determiner.determine_and_execute()
12
  return determine_output, execute_output
13
 
@@ -18,7 +18,8 @@ He turns the cup upside down, then walks to the garden.
18
  He puts the cup down in the garden, then walks to the garage.
19
  Where is the ball?""", 0.6], ["Given the task of building a house in the middle of a river, what are three strategies I could use to mitigate risk of flooding?", 0.6 ]]
20
 
21
- def create_reasoning_router_ui(cache_examples=False):
 
22
  with gr.Row():
23
  question = gr.Textbox(label="Enter your question here:")
24
  temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
@@ -27,6 +28,6 @@ def create_reasoning_router_ui(cache_examples=False):
27
  reasoning = gr.Textbox(label="Reasoning")
28
 
29
  generate_button = gr.Button(label="Generate")
30
- generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[question, temperature])
31
- gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[question, temperature], outputs=[reasoning_strategy, reasoning])
32
 
 
4
  openai_api_key = os.getenv("OPENAI_API_KEY")
5
 
6
 
7
+ def determine_and_execute(api_key,question, temperature):
8
  config = get_reasoning_router_config(temperature=temperature)
9
  config.temperature = temperature
10
+ determiner = ReasoningRouter(api_key=api_key, config=config, question=question, display=print)
11
  determine_output, execute_output = determiner.determine_and_execute()
12
  return determine_output, execute_output
13
 
 
18
  He puts the cup down in the garden, then walks to the garage.
19
  Where is the ball?""", 0.6], ["Given the task of building a house in the middle of a river, what are three strategies I could use to mitigate risk of flooding?", 0.6 ]]
20
 
21
+ def create_reasoning_router_ui(cache_examples=False):
22
+ api_key = gr.Textbox(label="You OpenAI API key", type="password")
23
  with gr.Row():
24
  question = gr.Textbox(label="Enter your question here:")
25
  temperature = gr.Slider(minimum=0, maximum=2, default=.7, label="Temperature")
 
28
  reasoning = gr.Textbox(label="Reasoning")
29
 
30
  generate_button = gr.Button(label="Generate")
31
+ generate_button.click(determine_and_execute, outputs=[reasoning_strategy, reasoning], inputs=[api_key, question, temperature])
32
+ gr.Examples(examples=examples, fn=determine_and_execute, cache_examples=cache_examples, inputs=[api_key, question, temperature], outputs=[reasoning_strategy, reasoning])
33
 
server.py CHANGED
@@ -17,9 +17,9 @@ def create_interface():
17
  create_reasoning_router_ui()
18
  with gr.Tab("Knowledge Domains"):
19
  create_knowledge_router_ui()
 
20
  interface.queue()
21
  interface.launch(server_name="0.0.0.0", server_port=7000)
22
 
23
-
24
  if __name__ == "__main__":
25
  create_interface()
 
17
  create_reasoning_router_ui()
18
  with gr.Tab("Knowledge Domains"):
19
  create_knowledge_router_ui()
20
+
21
  interface.queue()
22
  interface.launch(server_name="0.0.0.0", server_port=7000)
23
 
 
24
  if __name__ == "__main__":
25
  create_interface()