storm icon indicating copy to clipboard operation
storm copied to clipboard

how to run examples of ollama

Open verigle opened this issue 1 year ago • 2 comments

Traceback (most recent call last):
  File "/data/projects/stanford-oval/storm/examples/run_storm_wiki_ollama.py", line 25, in <module>
    from lm import OllamaClient
ModuleNotFoundError: No module named 'lm'

where can I find the source of src?

import os
import sys
from argparse import ArgumentParser

from dspy import Example

sys.path.append('./src')
from lm import OllamaClient
from rm import YouRM, BingSearch
from storm_wiki.engine import STORMWikiRunnerArguments, STORMWikiRunner, STORMWikiLMConfigs
from utils import load_api_key

verigle avatar Jul 29 '24 02:07 verigle

I was able to use ollama https://github.com/jaigouk/storm_wiki/blob/main/util/storm_runner.py#L132

jaigouk avatar Jul 29 '24 08:07 jaigouk

The ‘src’ folder has been renamed to ‘knowledge_storm’, but it is no longer necessary to include that line if you have installed starm via pip: pip install knowledge-storm. I have managed to get the example working with Ollama by making the following changes: On lines 18-28 change

import os
import sys
from argparse import ArgumentParser

from dspy import Example

sys.path.append('./src')
from lm import OllamaClient
from rm import YouRM, BingSearch
from storm_wiki.engine import STORMWikiRunnerArguments, STORMWikiRunner, STORMWikiLMConfigs
from utils import load_api_key

to

import os
from argparse import ArgumentParser

from knowledge_storm import STORMWikiRunnerArguments, STORMWikiRunner, STORMWikiLMConfigs
from knowledge_storm.lm import OllamaClient
from knowledge_storm.rm import YouRM, BingSearch
from knowledge_storm.utils import load_api_key

I have also removed the Example lines 70-138 (actually I have commented them out) and changed it to the GPT example sentences:

change

    runner = STORMWikiRunner(engine_args, lm_configs, rm)

    # Open LMs are generally weaker in following output format.
    # One way for mitigation is to add one-shot example to the prompt to exemplify the desired output format.
    # For example, we can add the following examples to the two prompts used in StormPersonaGenerator.
    # Note that the example should be an object of dspy.Example with fields matching the InputField
    # and OutputField in the prompt (i.e., dspy.Signature).
    find_related_topic_example = Example(
        topic="Knowledge Curation",
        related_topics="https://en.wikipedia.org/wiki/Knowledge_management\n"
                       "https://en.wikipedia.org/wiki/Information_science\n"
                       "https://en.wikipedia.org/wiki/Library_science\n"
    )
    gen_persona_example = Example(
        topic="Knowledge Curation",
        examples="Title: Knowledge management\n"
                 "Table of Contents: History\nResearch\n  Dimensions\n  Strategies\n  Motivations\nKM technologies"
                 "\nKnowledge barriers\nKnowledge retention\nKnowledge audit\nKnowledge protection\n"
                 "  Knowledge protection methods\n    Formal methods\n    Informal methods\n"
                 "  Balancing knowledge protection and knowledge sharing\n  Knowledge protection risks",
        personas="1. Historian of Knowledge Systems: This editor will focus on the history and evolution of knowledge curation. They will provide context on how knowledge curation has changed over time and its impact on modern practices.\n"
                 "2. Information Science Professional: With insights from 'Information science', this editor will explore the foundational theories, definitions, and philosophy that underpin knowledge curation\n"
                 "3. Digital Librarian: This editor will delve into the specifics of how digital libraries operate, including software, metadata, digital preservation.\n"
                 "4. Technical expert: This editor will focus on the technical aspects of knowledge curation, such as common features of content management systems.\n"
                 "5. Museum Curator: The museum curator will contribute expertise on the curation of physical items and the transition of these practices into the digital realm."
    )
    runner.storm_knowledge_curation_module.persona_generator.create_writer_with_persona.find_related_topic.demos = [
        find_related_topic_example]
    runner.storm_knowledge_curation_module.persona_generator.create_writer_with_persona.gen_persona.demos = [
        gen_persona_example]

    # A trade-off of adding one-shot example is that it will increase the input length of the prompt. Also, some
    # examples may be very long (e.g., an example for writing a section based on the given information), which may
    # confuse the model. For these cases, you can create a pseudo-example that is short and easy to understand to steer
    # the model's output format.
    # For example, we can add the following pseudo-examples to the prompt used in WritePageOutlineFromConv and
    # ConvToSection.
    write_page_outline_example = Example(
        topic="Example Topic",
        conv="Wikipedia Writer: ...\nExpert: ...\nWikipedia Writer: ...\nExpert: ...",
        old_outline="# Section 1\n## Subsection 1\n## Subsection 2\n"
                    "# Section 2\n## Subsection 1\n## Subsection 2\n"
                    "# Section 3",
        outline="# New Section 1\n## New Subsection 1\n## New Subsection 2\n"
                "# New Section 2\n"
                "# New Section 3\n## New Subsection 1\n## New Subsection 2\n## New Subsection 3"
    )
    runner.storm_outline_generation_module.write_outline.write_page_outline.demos = [write_page_outline_example]
    write_section_example = Example(
        info="[1]\nInformation in document 1\n[2]\nInformation in document 2\n[3]\nInformation in document 3",
        topic="Example Topic",
        section="Example Section",
        output="# Example Topic\n## Subsection 1\n"
               "This is an example sentence [1]. This is another example sentence [2][3].\n"
               "## Subsection 2\nThis is one more example sentence [1]."
    )
    runner.storm_article_generation.section_gen.write_section.demos = [write_section_example]

    topic = input('Topic: ')
    runner.run(
        topic=topic,
        do_research=args.do_research,
        do_generate_outline=args.do_generate_outline,
        do_generate_article=args.do_generate_article,
        do_polish_article=args.do_polish_article,
    )
    runner.post_run()
    runner.summary()

to:

    runner = STORMWikiRunner(engine_args, lm_configs, rm)

    topic = input('Topic: ')
    runner.run(
        topic=topic,
        do_research=args.do_research,
        do_generate_outline=args.do_generate_outline,
        do_generate_article=args.do_generate_article,
        do_polish_article=args.do_polish_article,
    )
    runner.post_run()
    runner.summary()

Do not forget to indicate the ollama model with "--model" when running the example (and of course be sure that ollama is running in the background". To run it with llama3.1:latest and ollama listening on localhost:11434:

python examples/run_storm_wiki_ollama.py \
    --model "llama3.1:latest" \
    --url "http://localhost" \
    --port 11434 \
    --output-dir OLLAMA_output \
    --retriever you \
    --do-research \
    --do-generate-outline \
    --do-generate-article \
    --do-polish-article

epuertas avatar Jul 29 '24 13:07 epuertas

close as resolved

Yucheng-Jiang avatar Aug 31 '24 11:08 Yucheng-Jiang