palladius / gemini-news-crawler

A GenAI news crawler in Ruby leveraging Gemini multimodality ability
MIT License
13 stars 1 forks source link

Install langchainrb + ArticleTool #1

Closed andreibondarev closed 6 months ago

andreibondarev commented 6 months ago

This PR installs langchainrb and illustrates how to build custom Tools.

Usage examples:

# Instantiate the LLM
llm = Langchain::LLM::GoogleVertexAI.new(project_id: ENV["GOOGLE_VERTEX_AI_PROJECT_ID"], region: "us-central1")
# Create a new Thread to keep track of the messages
thread = Langchain::Thread.new

# Instantiate tools
news_retriever = Langchain::Tool::NewsRetriever.new(api_key: ENV["NEWS_API_KEY"])
article_tool = ArticleTool.new

assistant = Langchain::Assistant.new(
  llm: llm,
  thread: thread,
  instructions: "You are a News Assistant.",
  tools: [news_retriever, article_tool]
)

assistant.add_message_and_run content:"What are the latest news from Google I/O?", auto_tool_execution: true

# Inspect the messages
assistant.thread.messages

assistant.add_message_and_run content:"Save the last one to the database", auto_tool_execution: true
andreibondarev commented 6 months ago

@palladius I'm still trying to figure out why an error is happening...

palladius commented 6 months ago

Thanks Andrei!!!

palladius commented 6 months ago

I also get error.