Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchApi Integration #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

SearchApi Integration #1

wants to merge 1 commit into from

Conversation

dremeika
Copy link
Collaborator

@dremeika dremeika commented Sep 14, 2023

Based on the customers' requests for native langchain integration, SearchApi is ready to invest in AI and LLM space, especially in open-source development.

  • This is our initial PR and later we want to improve it based on customers' and langchain users' feedback. Most likely changes will affect how the final results string is being built.
  • We are creating similar native integration in Python and JavaScript.
  • The next plan is to integrate into Java, Ruby, Go, and others.
  • Feel free to assign @SebastjanPrachovskij as a main reviewer for any SearchApi-related searches. We will be glad to help and support langchain development.

Usage

from langchain.utilities import SearchApiAPIWrapper
from langchain.llms.openai import OpenAI
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType

import os
os.environ["OPENAI_API_KEY"] = ""
os.environ["SEARCHAPI_API_KEY"] = ""

llm = OpenAI(temperature=0)
search = SearchApiAPIWrapper()
tools = [
    Tool(
        name="Intermediate Answer",
        func=search.run,
        description="useful for when you need to ask with search"
    )
]

self_ask_with_search = initialize_agent(tools, llm, agent=AgentType.SELF_ASK_WITH_SEARCH, verbose=True)
self_ask_with_search.run("Who lived longer: Plato, Socrates, or Aristotle?")

Output

> Entering new AgentExecutor chain...
 Yes.
Follow up: How old was Plato when he died?
Intermediate answer: eighty
Follow up: How old was Socrates when he died?
Intermediate answer: | Socrates | 
| -------- | 
| Born | c. 470 BC Deme Alopece, Athens | 
| Died | 399 BC (aged approximately 71) Athens | 
| Cause of death | Execution by forced suicide by poisoning | 
| Spouse(s) | Xanthippe, Myrto | 

Follow up: How old was Aristotle when he died?
Intermediate answer: 62 years
So the final answer is: Plato

> Finished chain.
'Plato'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants