### Run the AgentSearch Server Source: https://agent-search.readthedocs.io/en/latest/setup/quick_start.html Start the AgentSearch application server. Ensure all local setup and database population steps are completed first. ```bash python -m agent_search.app.server ``` -------------------------------- ### Start Postgres Database Source: https://agent-search.readthedocs.io/en/latest/setup/quick_start.html Start the PostgreSQL database service. This is required for local setup and data population. ```bash sudo service postgresql start ``` -------------------------------- ### Development Setup for AgentSearch Source: https://agent-search.readthedocs.io/en/latest/setup/installation.html Clone the repository and install AgentSearch in editable mode for development. This requires Git and Python 3. ```bash git clone https://github.com/SciPhi-AI/agent-search.git cd agent-search pip3 install -e . ``` -------------------------------- ### Development Setup for AgentSearch Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/installation.rst Clone the repository and install AgentSearch in editable mode for development. This requires git and pip3. ```console git clone https://github.com/SciPhi-AI/agent-search.git cd agent-search pip3 install -e . ``` -------------------------------- ### Run the AgentSearch Server Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Start the AgentSearch application server. This command should be executed from the root directory of the AgentSearch project. ```shell python -m agent_search.app.server ``` -------------------------------- ### Start Qdrant Service with Docker Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Run a Qdrant vector database instance using Docker. This command maps local storage for persistence. ```shell docker run -p 6333:6333 -p 6334:6334 -v $(pwd)/qdrant_storage:/qdrant/storage:z qdrant/qdrant ``` -------------------------------- ### Install AgentSearch with pip Source: https://agent-search.readthedocs.io/en/latest/setup/installation.html Use this command for a quick installation of AgentSearch. Ensure Python version 3.9 or higher is installed. ```bash pip install agent-search ``` -------------------------------- ### Install AgentSearch with pip Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/installation.rst Use this command for a quick installation of AgentSearch. Ensure Python version is compatible. ```console pip install agent-search ``` -------------------------------- ### Search RAG Endpoint Request Example Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst This example demonstrates how to call the /search_rag endpoint with specific parameters for search provider, LLM model, temperature, and top_p. The SCIPHI_API_KEY must be set. ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search_rag \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "Explain the Turing Test", "search_provider": "bing", "llm_model": "SciPhi/Sensei-7B-V1", "temperature": 0.2, "top_p": 0.95 }' ``` -------------------------------- ### Launch Postgres Database Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Start the PostgreSQL service. This command requires superuser privileges. ```shell sudo service postgresql start ``` -------------------------------- ### Search Endpoint Response Example Source: https://agent-search.readthedocs.io/en/latest/api/main.html This is an example of the JSON response structure from the Search endpoint, containing ranked search results with score, URL, title, text, dataset, and metadata. ```json [ { "score": 0.9219069895529107, "url": "https://en.wikipedia.org/wiki/Quantum%20field%20theory%20in%20curved%20spacetime", "title": "Quantum field theory in curved spacetime", "dataset": "wikipedia", "text": "These theories rely on general relativity to describe a curved background spacetime, and define a generalized quantum field theory to describe the behavior of quantum matter within that spacetime.", "metadata": {}, }, { "score": 0.8924581032960278, "url": "https://arxiv.org/abs/1308.6773", "title": "Quantum field theory on curved spacetime and the standard cosmological model", "dataset": "arxiv", "text": "Algebraic quantum field theory was originally developed to understand the relation between the local degrees of freedom of quantized fields and the observed multi-particle states. It was then observed by Dimock and Kay that it provides a good starting point for formulating a theory on a curved spacetime.", "metadata": "{\"timestamp\": \"1995-09-29T17:38:49\", \"yymm\": \"9509\", \"arxiv_id\": \"gr-qc/9509057 ....", }, ... ] ``` -------------------------------- ### Sample JSON Response for Completion Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst This is an example of the JSON response you can expect after making a completion request to the SciPhi API. ```json { "id":"cmpl-f03f53c15a174ffe89bdfc83507de7a9", "object":"text_completion", "created":389200, "model":"SciPhi/Sensei-7B-V1", "choices":[ { "index":0, "text":"The quest for the meaning of life is a profound and multifaceted in", "logprobs":null, "finish_reason":"length" } ], "usage": { "prompt_tokens":49, "total_tokens":65, "completion_tokens":16 } } ``` -------------------------------- ### Search RAG Endpoint Response Example Source: https://agent-search.readthedocs.io/en/latest/api/main.html An example of the response from the Search RAG endpoint, which includes the generated response text and a list of related queries. It may also include search results similar to the standard Search endpoint. ```json { "response": "The Turing Test is a measure of a machine's...", "related_queries": ["What are the origins of the Turing Test?", "How does the Turing Test work?", ...], "search_results" : [{ ...see above... }] } ``` -------------------------------- ### Custom Search Agent Workflow with RAG Source: https://agent-search.readthedocs.io/en/latest/_sources/index.rst Build a custom search agent workflow using RAG. This example specifies instructions for the task, constructs search context from results, and generates a JSON response. ```python from agent_search import SciPhi import json client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### Custom Search Agent Workflow with SciPhi Client Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Code your own custom search agent workflow by specifying instructions, performing a search, constructing search context, and generating a raw string completion. This example demonstrates retrieval augmented generation (RAG) and enforces a JSON response format. ```python from agent_search import SciPhi import json client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### Get Search RAG Response with SciPhi Client Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Use this to search and then summarize the result, generating related queries. Requires SCIPHI_API_KEY in the environment. ```python from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # {'response': "The latest news encompasses ... and its consequences [2].", 'related_queries': ['Details on the...', ...], 'search_results' : [...]} ``` -------------------------------- ### Generate RAG Response with AgentSearch Source: https://agent-search.readthedocs.io/en/latest/setup/quick_start.html Use the SciPhi `SearchAgent` for LLM RAG with AgentSearch. Set your API key and provide a query to get a response. ```bash export SCIPHI_API_KEY=MY_SCIPHI_API_KEY # Use the SciPhi `SearchAgent` for LLM RAG w/ AgentSearch python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" # ... Output ... # {"response": "\nFermat's Last Theorem is a significant result in number theory, stating that for any natural number n greater than 2, there are no solutions to the equation \\(a^n + b^n = c^n\\) where \\(a\), \\(b\), and \\(c\) are positive integers [5]. The theorem was first proposed by Pierre Fermat in the margins of his copy of Diophantus's \"Arithmetica\" in the 17th century, but it remained unproved for over three centuries [8]. The first case of the theorem to be proven was by Fermat himself for \(n = 4\), using a method of infinite descent [9]. Leonhard Euler later provided a proof for the case \(n = 3\), although his initial proof contained errors that were later corrected [9].\n\nThe theorem was finally proven in its entirety in 1995 by British mathematician Andrew Wiles, using sophisticated mathematical tools and techniques that were not available during Fermat's lifetime [10]. This breakthrough marked the end of a long period of mathematical speculation and the resolution of a major historical puzzle in mathematics [10]. The proof of Fermat's Last Theorem has been hailed as one of the most significant achievements in the history of mathematics, demonstrating the power of modern mathematical methods and the persistence of mathematical inquiry over centuries [10].\n\n", "other_queries": ["Details of Fermat's Last Theorem proof", "Historical impact of Fermat's Last Theorem", "Contributions of Andrew Wiles to mathematics", "Techniques used in the proof of Fermat's Last Theorem", "Evolution of number theory post-Fermat's Last Theorem"]} ``` -------------------------------- ### Code Custom Search Agent Workflow with RAG Source: https://agent-search.readthedocs.io/en/latest/index.html Build a custom search agent workflow using Retrieval-Augmented Generation (RAG). This example specifies instructions for the task, constructs search context, and generates a completion with a specified LLM model, enforcing a JSON response format. ```python from agent_search import SciPhi import json client = SciPhi() # Specify instructions for the task instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) # { # "summary": "\nFermat's Last Theorem is a mathematical proposition first prop ... ", # "other_queries": ["The role of elliptic curves in the proof of Fermat's Last Theorem", ...] # } ``` -------------------------------- ### Get Search RAG Response Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Retrieves a search RAG (Retrieval-Augmented Generation) response from the API. ```APIDOC ## SciPhi.get_search_rag_response() ### Description Retrieves a search RAG (Retrieval-Augmented Generation) response from the API. ### Method `get_search_rag_response` ### Parameters #### Path Parameters - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use. - **llm_model** (str) - Optional - The language model to use. Defaults to 'SciPhi/Sensei-7B-V1'. - **temperature** (int) - Optional - The temperature setting for the query. Defaults to 0.2. - **top_p** (int) - Optional - The top-p setting for the query. Defaults to 0.95. ### Returns str - A string containing the completed text. ``` -------------------------------- ### SciPhi Client Initialization and Usage Source: https://agent-search.readthedocs.io/en/latest/_sources/python_client/main.rst Demonstrates how to initialize the SciPhi client and use its methods for search and RAG responses. ```APIDOC ## SciPhi Client Initialization and Usage ### Description This section shows how to initialize the `SciPhi` client and use its core methods like `get_search_rag_response` and `search`. ### Method ```python from agent_search import SciPhi # Initialize the client (requires SCIPHI_API_KEY in environment) client = SciPhi() # Example: Get a search RAG response agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # Example: Perform a standalone search search_response = client.search(query='Quantum Field Theory', search_provider='agent-search') print(search_response) ``` ### Parameters #### `get_search_rag_response` Parameters - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use (e.g., 'bing', 'agent-search'). - **llm_model** (str) - Optional - The language model to use (defaults to 'SciPhi/Sensei-7B-V1'). - **temperature** (int) - Optional - The temperature setting for the query (defaults to 0.2). - **top_p** (int) - Optional - The top-p setting for the query (defaults to 0.95). #### `search` Parameters - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use (e.g., 'agent-search'). ### Response #### `get_search_rag_response` Success Response - **response** (str) - The summarized response from the RAG process. - **related_queries** (List[str]) - A list of related queries generated based on the search. - **search_results** (List[Dict]) - The raw search results. #### `search` Success Response - Returns a list of dictionaries, where each dictionary represents a search result and may contain fields like `score`, `url`, and `metadata`. ``` -------------------------------- ### SciPhi Client Initialization Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Initialize the SciPhi client with your API key and base URL. ```APIDOC from sciphi_api_client import SciPhi client = SciPhi(api_base="https://api.sciphi.com", api_key="YOUR_API_KEY") ``` -------------------------------- ### Populate Vector Database (Qdrant) Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Populate the Qdrant vector database from the PostgreSQL database. Use --delete_existing=True to clear existing data before populating. ```shell python -m agent_search.scripts.populate_qdrant_from_postgres run --delete_existing=True ``` -------------------------------- ### Populate Postgres Database from Hugging Face Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Populate the PostgreSQL database with data from Hugging Face. This command is used for initial data loading. ```shell python -m agent_search.scripts.populate_postgres_from_hf run ``` -------------------------------- ### Call Pre-configured Search Agent Endpoint Source: https://agent-search.readthedocs.io/en/latest/index.html Use the SciPhi client to perform a search, then summarize the results and generate related queries. Requires SCIPHI_API_KEY to be set in the environment. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # {'response': "The latest news encompasses ... and its consequences [2].", 'related_queries': ['Details on the...', ...], 'search_results' : [...]} ``` -------------------------------- ### Custom Search Agent Workflow with Completion Source: https://agent-search.readthedocs.io/en/latest/_sources/python_client/main.rst Illustrates how to build a custom search agent workflow using search and completion methods. ```APIDOC ## Custom Search Agent Workflow with Completion ### Description This section demonstrates how to construct a custom search agent workflow by combining search queries with the `completion` method for advanced text generation tasks, such as Retrieval Augmented Generation (RAG). ### Method ```python from agent_search import SciPhi import json client = SciPhi() # Define task instructions and query instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # Perform a search to gather context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prepare the prompt for completion, enforcing JSON output json_response_prefix = '{"summary":' formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}" # Generate completion using a specified language model completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") # Parse and print the JSON response print(json.loads(completion)) ``` ### Parameters #### `completion` Parameters - **prompt** (str) - Required - The prompt for generating completion. - **llm_model_name** (str) - Optional - The language model to use (defaults to 'SciPhi/Sensei-7B-V1'). - **llm_max_tokens_to_sample** (int) - Optional - The maximum number of tokens to sample (defaults to 1024). - **llm_temperature** (float) - Optional - The temperature setting for the completion (defaults to 0.2). - **llm_top_p** (float) - Optional - The top-p setting for the completion (defaults to 0.90). ### Response #### `completion` Success Response - Returns a string containing the generated text completion. The example shows parsing this into a JSON object with 'summary' and 'other_queries' fields. ``` -------------------------------- ### Perform a Search with AgentSearch Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Set your API key and run a search query using the AgentSearch CLI. Replace 'MY_SCIPHI_API_KEY' with your actual key and 'Your Search Query' with your desired search term. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY python -m agent_search.scripts.run_search run --query="Your Search Query" ``` -------------------------------- ### Perform RAG Search and Summarization Source: https://agent-search.readthedocs.io/en/latest/_sources/index.rst Use the SciPhi client to perform a search, then summarize the results and generate related queries. Requires SCIPHI_API_KEY in the environment. ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() # Search, then summarize result and generate related queries agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) # {'response': "The latest news encompasses ... and its consequences [2].", 'related_queries': ['Details on the...', ...], 'search_results' : [...]} ``` -------------------------------- ### Populate Postgres Database Source: https://agent-search.readthedocs.io/en/latest/setup/quick_start.html Populate the PostgreSQL database from Hugging Face. This script is used to load data into the database. ```bash python -m agent_search.scripts.populate_postgres_from_hf run ``` -------------------------------- ### Completion Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Generates a completion string for a given prompt using the SciPhi API. ```APIDOC ## SciPhi.completion() ### Description Generates a completion string for a given prompt using the SciPhi API. ### Method `completion` ### Parameters #### Path Parameters - **prompt** (str) - Required - The prompt for generating completion. - **llm_model_name** (str) - Optional - The language model to use. Defaults to 'SciPhi/Sensei-7B-V1'. - **llm_max_tokens_to_sample** (int) - Optional - Maximum number of tokens for the sample. Defaults to 1024. - **llm_temperature** (float) - Optional - The temperature setting for the query. Defaults to 0.2. - **llm_top_p** (float) - Optional - The top-p setting for the query. Defaults to 0.90. ### Returns Dict - A dictionary containing the generated completion. ### Raises **ImportError** – If the sciphi-synthesizer package is not installed. ``` -------------------------------- ### Perform Standalone Search with AgentSearch Engine Source: https://agent-search.readthedocs.io/en/latest/index.html Instantiate the SciPhi client and perform a search using the AgentSearch engine. ```python from agent_search import SciPhi client = SciPhi() # Perform a search search_response = client.search(query='Quantum Field Theory', search_provider='agent-search') print(search_response) # [{ 'score': '.89', 'url': 'https://...', 'metadata': {...} } ``` -------------------------------- ### Search Client Methods Source: https://agent-search.readthedocs.io/en/latest/_sources/python_client/main.rst This section details the methods available for interacting with the search functionality, including parameters for controlling the generation process and closing the client. ```APIDOC ## Search Client Methods ### `__init__` Initializes the search client with optional parameters for controlling the language model's generation. #### Parameters - **llm_max_tokens_to_sample** (int) - Maximum number of tokens for the sample. - **llm_temperature** (float) - The temperature setting for the query. - **llm_top_p** (float) - The top-p setting for the query. ### `close` Closes the HTTP client. #### Method `close(self)` #### Returns None ``` -------------------------------- ### Generate RAG Response with AgentSearch (OpenAI) Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Generate a RAG response using OpenAI's gpt-3.5-turbo model. Set both SCIPHI_API_KEY and OPENAI_API_KEY environment variables. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY export OPENAI_API_KEY=MY_OPENAI_KEY # Use OpenAI `gpt-3.5-turbo` for LLM generation python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" --llm_provider_name=openai --llm_model_name=gpt-3.5-turbo ``` -------------------------------- ### LLM Completions Endpoint Source: https://agent-search.readthedocs.io/en/latest/api/main.html This endpoint allows you to use the Sensei model directly for purposes other than the provided Search RAG. It is compatible with OpenAI's API specification. ```APIDOC ## POST /v1/completions ### Description Provides direct access to the SciPhi Sensei model, compatible with OpenAI's API specification. ### Method POST ### Endpoint https://api.sciphi.ai/v1/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use, e.g., "SciPhi/Sensei-7B-V1". - **prompt** (string) - Required - The prompt to send to the model. - **temperature** (number) - Optional - Controls randomness, 0.0 for deterministic output. ### Request Example ```bash export SEARCH_CONTEXT="N/A" export RESPONSE_PREFIX='{"response":' curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nWhat is the meaning of life?\n\nSearch Results:\n${SEARCH_CONTEXT}\n\nQuery:\nWhat is the meaning of life?\n### Response:\n${RESPONSE_PREFIX}", "temperature": 0.0 }' ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of object, e.g., "text_completion". - **created** (integer) - Timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **text** (string) - The generated text. - **logprobs** (null) - Log probabilities (currently null). - **finish_reason** (string) - Reason for finishing generation (e.g., "length"). - **usage** (object) - Token usage information. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **total_tokens** (integer) - Total number of tokens used. - **completion_tokens** (integer) - Number of tokens in the completion. #### Response Example ```json { "id":"cmpl-f03f53c15a174ffe89bdfc83507de7a9", "object":"text_completion", "created":389200, "model":"SciPhi/Sensei-7B-V1", "choices":[ { "index":0, "text":"The quest for the meaning of life is a profound and multifaceted in", "logprobs":null, "finish_reason":"length" } ], "usage": { "prompt_tokens":49, "total_tokens":65, "completion_tokens":16 } } ``` ``` -------------------------------- ### Make a Completion Request with Curl Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst Use this curl command to send a completion request to the SciPhi API. Ensure your SCIPHI_API_KEY is set and the SEARCH_CONTEXT and RESPONSE_PREFIX environment variables are configured as needed. ```bash export SEARCH_CONTEXT="N/A" export RESPONSE_PREFIX='{"response":' curl https://api.sciphi.ai/v1/completions \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -d '{ "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nWhat is the meaning of life?\n\nSearch Results:\n${SEARCH_CONTEXT}\n\nQuery:\nWhat is the meaning of life?\n### Response:\n${RESPONSE_PREFIX}", "temperature": 0.0 }' ``` -------------------------------- ### Generate RAG Response with OpenAI Source: https://agent-search.readthedocs.io/en/latest/setup/quick_start.html Configure AgentSearch to use OpenAI's GPT-3.5-turbo model for RAG responses by setting API keys and specifying the LLM provider and model name. ```bash export SCIPHI_API_KEY=MY_SCIPHI_API_KEY export OPENAI_API_KEY=MY_OPENAI_KEY # Use OpenAI `gpt-3.5-turbo` for LLM generation python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" --llm_provider_name=openai --llm_model_name=gpt-3.5-turbo ``` -------------------------------- ### Generate RAG Response with AgentSearch (SciPhi) Source: https://agent-search.readthedocs.io/en/latest/_sources/setup/quick_start.rst Generate a RAG response using the SciPhi SearchAgent. Ensure your SCIPHI_API_KEY is set. ```shell export SCIPHI_API_KEY=MY_SCIPHI_API_KEY # Use the SciPhi `SearchAgent` for LLM RAG w/ AgentSearch python -m agent_search.scripts.run_rag run --query="What is Fermat's last theorem?" # ... Output ... # {"response": "\nFermat's Last Theorem is a significant result in number theory, stating that for any natural number n greater than 2, there are no solutions to the equation \\(a^n + b^n = c^n\\) where \\(a\), \\(b\), and \\(c\) are positive integers [5]. The theorem was first proposed by Pierre de Fermat in the margins of his copy of Diophantus's \"Arithmetica\" in the 17th century, but it remained unproved for over three centuries [8]. The first case of the theorem to be proven was by Fermat himself for \(n = 4\), using a method of infinite descent [9]. Leonhard Euler later provided a proof for the case \(n = 3\), although his initial proof contained errors that were later corrected [9].\n\nThe theorem was finally proven in its entirety in 1995 by British mathematician Andrew Wiles, using sophisticated mathematical tools and techniques that were not available during Fermat's lifetime [10]. This breakthrough marked the end of a long period of mathematical speculation and the resolution of a major historical puzzle in mathematics [10]. The proof of Fermat's Last Theorem has been hailed as one of the most significant achievements in the history of mathematics, demonstrating the power of modern mathematical methods and the persistence of mathematical inquiry over centuries [10].\n\n", "other_queries": ["Details of Fermat's Last Theorem proof", "Historical impact of Fermat's Last Theorem", "Contributions of Andrew Wiles to mathematics", "Techniques used in the proof of Fermat's Last Theorem", "Evolution of number theory post-Fermat's Last Theorem"]} ``` -------------------------------- ### Perform a Search RAG Query using cURL Source: https://agent-search.readthedocs.io/en/latest/api/main.html This cURL command demonstrates how to use the Search RAG endpoint, specifying the query, search provider, language model, and generation parameters like temperature and top_p. Ensure your API key is set. ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search_rag \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "query": "Explain the Turing Test", "search_provider": "bing", "llm_model": "SciPhi/Sensei-7B-V1", "temperature": 0.2, "top_p": 0.95 }' ``` -------------------------------- ### Perform a Search Query with API Key Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst Use this cURL command to send a search query to the /search endpoint. Ensure your SCIPHI_API_KEY environment variable is set. ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "What is quantum field theory in curved spacetime?"}' ``` -------------------------------- ### Completions Endpoint Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst This endpoint allows you to generate text completions based on a given prompt, model, and temperature. It is compatible with OpenAI's API specification. ```APIDOC ## POST /v1/completions ### Description Generates text completions using a specified model and prompt. ### Method POST ### Endpoint https://api.sciphi.ai/v1/completions ### Parameters #### Request Body - **model** (string) - Required - The model to use for completions (e.g., "SciPhi/Sensei-7B-V1"). - **prompt** (string) - Required - The input prompt for text generation. - **temperature** (number) - Optional - Controls randomness. Lower values make output more focused and deterministic. ### Request Example ```json { "model": "SciPhi/Sensei-7B-V1", "prompt": "### Instruction:\n\nQuery:\nWhat is the meaning of life?\n\nSearch Results:\n${SEARCH_CONTEXT}\n\nQuery:\nWhat is the meaning of life?\n### Response:\n${RESPONSE_PREFIX}", "temperature": 0.0 } ``` ### Response #### Success Response (200) - **id** (string) - Unique identifier for the completion. - **object** (string) - Type of the object returned (e.g., "text_completion"). - **created** (integer) - Timestamp of creation. - **model** (string) - The model used for the completion. - **choices** (array) - A list of completion choices. - **index** (integer) - Index of the choice. - **text** (string) - The generated text. - **logprobs** (null) - Log probabilities (currently null). - **finish_reason** (string) - The reason the completion finished (e.g., "length"). - **usage** (object) - Token usage information. - **prompt_tokens** (integer) - Number of tokens in the prompt. - **total_tokens** (integer) - Total number of tokens used. - **completion_tokens** (integer) - Number of tokens in the completion. #### Response Example ```json { "id":"cmpl-f03f53c15a174ffe89bdfc83507de7a9", "object":"text_completion", "created":389200, "model":"SciPhi/Sensei-7B-V1", "choices":[ { "index":0, "text":"The quest for the meaning of life is a profound and multifaceted in", "logprobs":null, "finish_reason":"length" } ], "usage": { "prompt_tokens":49, "total_tokens":65, "completion_tokens":16 } } ``` ``` -------------------------------- ### SciPhi.completion Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Generates a text completion based on a formatted prompt and a specified language model. Useful for custom workflows. ```APIDOC ## SciPhi.completion() ### Description Generates a text completion based on a formatted prompt and a specified language model. Useful for custom workflows. ### Parameters - **prompt** (string) - Required - The formatted prompt for text generation. - **llm_model_name** (string) - Required - The name of the language model to use for completion. ### Request Example ```python from agent_search import SciPhi import json client = SciPhi() instruction = "Your task is to perform retrieval augmented generation (RAG) over the given query and search results. Return your answer in a json format that includes a summary of the search results and a list of related queries." query = "What is Fermat's Last Theorem?" # construct search context search_response = client.search(query=query, search_provider='agent-search') search_context = "\n\n".join( f"{idx + 1}. Title: {item['title']}\nURL: {item['url']}\nText: {item['text']}" for idx, item in enumerate(search_response) ).encode('utf-8') # Prefix to enforce a JSON response json_response_prefix = '{"summary":' # Prepare a prompt formatted_prompt = f"### Instruction:{instruction}\n\nQuery:\n{query}\n\nSearch Results:\n${search_context}\n\nQuery:\n{query}\n### Response:\n{json_response_prefix}", # Generate a raw string completion with Sensei-7B-V1 completion = json_response_prefix + client.completion(formatted_prompt, llm_model_name="SciPhi/Sensei-7B-V1") print(json.loads(completion)) ``` ### Response #### Success Response (200) - **completion string** - The generated text completion. ``` -------------------------------- ### Perform Standalone Search Source: https://agent-search.readthedocs.io/en/latest/_sources/index.rst Execute a standalone search using the AgentSearch client and the 'agent-search' provider. ```python from agent_search import SciPhi client = SciPhi() # Perform a search search_response = client.search(query='Quantum Field Theory', search_provider='agent-search') print(search_response) # [{ 'score': '.89', 'url': 'https://...', 'metadata': {...} } ``` -------------------------------- ### SciPhi.close Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Closes the client session, releasing any resources. ```APIDOC ## SciPhi.close() ### Description Closes the client session, releasing any resources. ### Method `close()` ### Parameters None ### Request Example ```python from agent_search import SciPhi client = SciPhi() # ... perform operations ... client.close() ``` ### Response No specific response body is detailed, implies successful execution. ``` -------------------------------- ### SciPhi.get_search_rag_response Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Retrieves a summarized response and related queries based on a given query and search provider. It utilizes a specified LLM model for generation. ```APIDOC ## SciPhi.get_search_rag_response() ### Description Retrieves a summarized response and related queries based on a given query and search provider. It utilizes a specified LLM model for generation. ### Parameters - **query** (string) - Required - The search query. - **search_provider** (string) - Required - The search engine to use (e.g., 'bing', 'agent-search'). - **llm_model** (string) - Required - The language model to use for generating the response. ### Request Example ```python # Requires SCIPHI_API_KEY in the environment from agent_search import SciPhi client = SciPhi() agent_summary = client.get_search_rag_response(query='latest news', search_provider='bing', llm_model='SciPhi/Sensei-7B-V1') print(agent_summary) ``` ### Response #### Success Response (200) - **response** (string) - The summarized response. - **related_queries** (list) - A list of related search queries. - **search_results** (list) - A list of search result objects. ``` -------------------------------- ### Search Source: https://agent-search.readthedocs.io/en/latest/python_client/main.html Performs a search query using the SciPhi API. ```APIDOC ## SciPhi.search() ### Description Performs a search query using the SciPhi API. ### Method `search` ### Parameters #### Path Parameters - **query** (str) - Required - The search query string. - **search_provider** (str) - Required - The search provider to use. ### Returns List[Dict] - A list of search results w/ fields that correspond with SearchResult. ``` -------------------------------- ### Search Endpoint Source: https://agent-search.readthedocs.io/en/latest/_sources/api/main.rst Allows you to fetch related search results for a given query using the AgentSearch framework. ```APIDOC ## POST /search ### Description This endpoint interacts with the Retriever module of the AgentSearch-Infra codebase, allowing you to search for related documents based on the provided queries. ### Method POST ### Endpoint /search ### Parameters #### Request Body - **query** (string) - Required - A string that contains the query you wish to search for. ### Response #### Success Response (200) A list AgentSearchResult objects. Each object contains the following fields: - **score** (float) - The ranked relevance score of the document. - **url** (string) - The URL of the document. - **title** (string) - The title of the document. - **text** (string) - The text of the document. - **metadata** (string) - A stringified JSON object containing the document's metadata. - **dataset** (string) - The name of the dataset the document belongs to. ### Request Example ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "What is quantum field theory in curved spacetime?"}' ``` ### Response Example ```json [ { "score": 0.9219069895529107, "url": "https://en.wikipedia.org/wiki/Quantum%20field%20theory%20in%20curved%20spacetime", "title": "Quantum field theory in curved spacetime", "dataset": "wikipedia", "text": "These theories rely on general relativity to describe a curved background spacetime, and define a generalized quantum field theory to describe the behavior of quantum matter within that spacetime.", "metadata": "{}" }, { "score": 0.8924581032960278, "url": "https://arxiv.org/abs/1308.6773", "title": "Quantum field theory on curved spacetime and the standard cosmological model", "dataset": "arxiv", "text": "Algebraic quantum field theory was originally developed to understand the relation between the local degrees of freedom of quantized fields and the observed multi-particle states. It was then observed by Dimock and Kay that it provides a good starting point for formulating a theory on a curved spacetime.", "metadata": "{\"timestamp\": \"1995-09-29T17:38:49\", \"yymm\": \"9509\", \"arxiv_id\": \"gr-qc/9509057 ...." }, ... ] ``` ``` -------------------------------- ### Search Endpoint Source: https://agent-search.readthedocs.io/en/latest/api/main.html This endpoint interacts with the Retriever module of the AgentSearch-Infra codebase, allowing you to search for related documents based on the provided queries. ```APIDOC ## Search Endpoint ### Description This endpoint allows you to fetch related search results for a given query. The results are powered by the AgentSearch framework and dataset. ### Method POST ### Endpoint /search ### Parameters #### Request Body - **query** (string) - Required - The query you wish to search for. ### Response #### Success Response (200) A list AgentSearchResult objects. Each object contains the following fields: - **score** (float) - The ranked relevance score of the document. - **url** (string) - The URL of the document. - **title** (string) - The title of the document. - **text** (string) - The text of the document. - **metadata** (string) - A stringified JSON object containing the document’s metadata. - **dataset** (string) - The name of the dataset the document belongs to. ### Request Example ```bash export SCIPHI_API_KEY=${MY_API_KEY} curl -X POST https://api.sciphi.ai/search \ -H "Authorization: Bearer $SCIPHI_API_KEY" \ -H "Content-Type: application/json" \ -d '{"query": "What is quantum field theory in curved spacetime?"}' ``` ### Response Example ```json [ { "score": 0.9219069895529107, "url": "https://en.wikipedia.org/wiki/Quantum%20field%20theory%20in%20curved%20spacetime", "title": "Quantum field theory in curved spacetime", "dataset": "wikipedia", "text": "These theories rely on general relativity to describe a curved background spacetime, and define a generalized quantum field theory to describe the behavior of quantum matter within that spacetime.", "metadata": "{}" }, { "score": 0.8924581032960278, "url": "https://arxiv.org/abs/1308.6773", "title": "Quantum field theory on curved spacetime and the standard cosmological model", "dataset": "arxiv", "text": "Algebraic quantum field theory was originally developed to understand the relation between the local degrees of freedom of quantized fields and the observed multi-particle states. It was then observed by Dimock and Kay that it provides a good starting point for formulating a theory on a curved spacetime.", "metadata": "{\"timestamp\": \"1995-09-29T17:38:49\", \"yymm\": \"9509\", \"arxiv_id\": \"gr-qc/9509057 ...."}" }, ... ] ``` ```