Skip to content

Commit cb77535

Browse files
chore: add llamaindex chat agent sample
1 parent 4045c4a commit cb77535

6 files changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Literature Chat Agent
2+
3+
An AI assistant using Llamaindex and Tavily search for literature research and recommendations.
4+
5+
## Requirements
6+
7+
- Python 3.11+
8+
- OpenAI API key
9+
- Tavily API key
10+
11+
## Installation
12+
13+
```bash
14+
uv venv -p 3.11 .venv
15+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
16+
uv sync
17+
```
18+
19+
Set your API keys as environment variables in .env
20+
21+
```bash
22+
OPENAI_API_KEY=your_anthropic_api_key
23+
TAVILY_API_KEY=your_tavily_api_key
24+
```
25+
26+
## Usage
27+
28+
```bash
29+
uipath run agent 'uipath run agent '{"user_msg": "Tell me about 1984 by George Orwell"}''
30+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
flowchart TB
2+
__start__(__start__)
3+
chat(chat)
4+
__end__(__end__)
5+
__start__ --> |ChatInput|chat
6+
chat --> |StopEvent|__end__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"workflows": {
3+
"agent": "main.py:agent"
4+
}
5+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
3+
from llama_index.core.agent.workflow import FunctionAgent
4+
from llama_index.llms.openai import OpenAI
5+
from llama_index.tools.tavily_research import TavilyToolSpec
6+
7+
llm = OpenAI(model="gpt-4o-mini")
8+
tavily_tool = TavilyToolSpec(api_key=os.environ["TAVILY_API_KEY"])
9+
10+
SYSTEM_PROMPT = (
11+
"You are an advanced AI assistant specializing in book research and literature analysis. "
12+
"Your primary functions are:\n\n"
13+
"1. Book Information Research: Gather comprehensive information about books, including plot summaries, "
14+
"themes, publishing details, sales performance, critical reception, and awards.\n"
15+
"2. Author Research: Provide detailed information about authors, translators, editors, and other "
16+
"publishing industry professionals.\n"
17+
"3. Book Recommendations: Suggest books based on user preferences, genres, themes, or similar books "
18+
"they have enjoyed.\n"
19+
"4. Publishing Industry Analysis: Analyze trends, bestseller data, genre popularity, and insights "
20+
"from the literary world.\n"
21+
"5. Book Trivia and Facts: Share interesting facts, behind-the-scenes stories, and trivia about "
22+
"books, authors, and the publishing industry.\n\n"
23+
"Use the search tool for recent or factual information. "
24+
"Remember previous messages and maintain context across the discussion."
25+
)
26+
27+
agent = FunctionAgent(
28+
tools=tavily_tool.to_tool_list(),
29+
llm=llm,
30+
system_prompt=SYSTEM_PROMPT
31+
)
32+
33+
async def chat(user_input: str) -> str:
34+
response = await agent.run(user_msg=user_input)
35+
return str(response)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[project]
2+
name = "chat-agent"
3+
version = "0.0.1"
4+
description = "chat-agent"
5+
authors = [{ name = "John Doe", email = "john.doe@myemail.com" }]
6+
dependencies = [
7+
"uipath-llamaindex>=0.5.0, <0.6.0",
8+
"llama-index-llms-openai>=0.6.10",
9+
"llama-index-tools-tavily-research>=0.4.2",
10+
"llama-index-llms-openai>=0.6.18"
11+
]
12+
requires-python = ">=3.11"
13+
14+
15+
[dependency-groups]
16+
dev = [
17+
"uipath-dev>=0.0.19",
18+
]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://cloud.uipath.com/draft/2024-12/uipath",
3+
"runtimeOptions": {
4+
"isConversational": false
5+
},
6+
"packOptions": {
7+
"fileExtensionsIncluded": [],
8+
"filesIncluded": [],
9+
"filesExcluded": [],
10+
"directoriesExcluded": [],
11+
"includeUvLock": true
12+
},
13+
"functions": {}
14+
}

0 commit comments

Comments
 (0)