Skip to content

Instantly share code, notes, and snippets.

@mattlindsey
Last active April 25, 2024 01:08
Show Gist options
  • Save mattlindsey/07d99c97ca7070f89c0bd7fad6c89bd7 to your computer and use it in GitHub Desktop.
Save mattlindsey/07d99c97ca7070f89c0bd7fad6c89bd7 to your computer and use it in GitHub Desktop.
Story writing assistant ruby code
module Langchain
# Langchain::StoryWritingAssistant is the class that handles story writing assistant methods
class StoryWritingAssistant < Assistant
attr_accessor :thread
attr_reader :tools
instructions = <<~INST
I am a writing assistant.
I can help you write stories and more.
And I can help you with research and questions about your story.
INST
# @param llm [Langchain::LLM::Base] LLM instance that the assistant will use
def initialize(llm)
thread = Thread.new,
tools = [Tool::Wikipedia.new]
super(llm: llm, thread: thread, instructions: instructions, tools: tools)
end
# Give the assistant a story to work with
#
# @param content [String] The content of the message
def create_story_message(story:)
add_message(content: "The story is: " + story, role: "user")
end
# Ask the writing assistant about the story
def ask(question:)
add_message_and_run(content: question, auto_tool_execution: true)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment