Spaces:
Running
Running
File size: 2,235 Bytes
ce90730 152dfa1 2fb0169 ce90730 2fb0169 36aeeec ce90730 152dfa1 ce90730 2fb0169 ce90730 152dfa1 9a8ebcf 2fb0169 ce90730 2fb0169 ce90730 08152a0 ce90730 2fb0169 ce90730 2fb0169 ce90730 6db8557 ce90730 7cc108b ce90730 2fb0169 ce90730 2fb0169 71a34b2 ce90730 2fb0169 ce90730 71a34b2 2fb0169 ce90730 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import os
from typing import Optional
import json
from pydantic import Field, BaseModel
from omegaconf import OmegaConf
import requests
from vectara_agentic.agent import Agent
from vectara_agentic.tools import VectaraToolFactory, ToolsFactory
from dotenv import load_dotenv
load_dotenv(override=True)
initial_prompt = "How can I help you today?"
def create_assistant_tools(cfg):
class QueryCona(BaseModel):
query: str = Field(description="The user query.")
vec_factory = VectaraToolFactory(
vectara_api_key=cfg.api_key,
vectara_corpus_key=cfg.corpus_key
)
summarizer = 'vectara-summary-table-md-query-ext-jan-2025-gpt-4o'
ask_ti = vec_factory.create_rag_tool(
tool_name = "ask_cona",
tool_description = """
Given a user query,
returns a response to a user question about bottling companies.
""",
tool_args_schema = QueryCona,
reranker = "slingshot", rerank_k = 100,
n_sentences_before = 2, n_sentences_after = 2, lambda_val = 0.01,
vectara_summarizer = summarizer,
summary_num_results = 20,
include_citations = True,
verbose = True
)
return [ask_ti] + ToolsFactory().guardrail_tools()
def initialize_agent(_cfg, agent_progress_callback=None):
bot_instructions = """
- You are a helpful assistant, with expertise in products from coca cola and other bottling companies.
- Use the ask_coma tool to answer most questions about any products related to coca cola.
"""
agent = Agent(
tools=create_assistant_tools(_cfg),
topic="Cona services and coca cola",
custom_instructions=bot_instructions,
agent_progress_callback=agent_progress_callback,
)
agent.report()
return agent
def get_agent_config() -> OmegaConf:
cfg = OmegaConf.create({
'corpus_key': str(os.environ['VECTARA_CORPUS_KEY']),
'api_key': str(os.environ['VECTARA_API_KEY']),
'examples': os.environ.get('QUERY_EXAMPLES', None),
'demo_name': "Cona Demo",
'demo_welcome': "Cona Assistant.",
'demo_description': "This assistant can help you with any questions about Cona Serices."
})
return cfg
|