langchain icon indicating copy to clipboard operation
langchain copied to clipboard

I like to write long sentences

Open miracle777 opened this issue 2 years ago • 5 comments

Why can I only create short records when using LangChain? When I use the API for GPT-3, I can create long sentences. I want to be able to create long sentences with what I get from LangChain's search tool. But if I don't have enough tools, I get an error. I want to know what this tool is.

miracle777 avatar Feb 03 '23 01:02 miracle777

do you have a code snippet and stack trace?

hwchase17 avatar Feb 03 '23 05:02 hwchase17

I will post the code I am trying with Google Colab.

I just tested it again and could not reproduce the repeated error. But I will post a picture of the error without the tool in the middle of the process.

I am in the process of writing the code, so I have a lot of comments.

# パッケージのインストール
!pip install langchain
!pip install openai
!pip install google-search-results

# 環境変数の準備
import os
os.environ["OPENAI_API_KEY"] = "***"
#SerpAPI
os.environ["SERPAPI_API_KEY"] = "***"

from langchain.agents import initialize_agent, Tool
from langchain.llms import OpenAI
from langchain import LLMMathChain, SerpAPIWrapper

from langchain.chains import LLMChain, SimpleSequentialChain
from langchain.prompts import PromptTemplate

llm = OpenAI(temperature=0.5)
search = SerpAPIWrapper()
llm_math_chain = LLMMathChain(llm=llm, verbose=True)
tools = [
    Tool(
        name = "Search",
        func=search.run,
        description="useful for when you need to answer questions about current events"
    ),
    Tool(
        name="Calculator",
        func=llm_math_chain.run,
        description="useful for when you need to answer questions about math"
    )
]


llm = OpenAI(temperature=0)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
agent.run("名古屋城について日本語で1000文字で書いてください")


#llm = OpenAI(temperature=.7)
#template = """検索結果から1000文字で文章を作ってください。



#"""

# Concatenate the search results with the question
##prompt = asktxt + "この検索結果で文章を書いてください。"

# Generate text based on the modified prompt
#llm.run(prompt)


スクリーンショット_20230203_161225

miracle777 avatar Feb 03 '23 07:02 miracle777

@miracle777 If you like the output to be longer, you can increase the max_tokens parameter in your llm. Example below:

llm = OpenAI(temperature=0, max_tokens=1500)

Hope this helps :)

nickscamara avatar Feb 03 '23 15:02 nickscamara

Thanks for letting us know. I no longer get the "no tool" error. Thank you very much.

Is the reason why I cannot generate long sentences in the search results because the number of characters I get in the search results is too small?

But thank you for solving the "no tool" error. Thank you very much.

スクリーンショット_20230204_003935

miracle777 avatar Feb 03 '23 15:02 miracle777

Thank you very much. I had set up a double llm in the program source. After correcting it, I was able to generate this long text.

But in Japanese, it doesn't seem to generate long sentences as I would like. Maybe I'm not asking the right question.

Finished chain. Tokugawa Ieyasu was the founder and first shōgun of the Tokugawa Shogunate of Japan, which ruled Japan from 1603 until the Meiji Restoration in 1868. He was one of the three "Great Unifiers" of Japan, along with his former lord Oda Nobunaga and fellow Oda subordinate Toyotomi Hideyoshi. Tokugawa Ieyasu was separated from his parents at an early age. His mother was forced to leave the household because of shifting clan alliances, and, when he was four years old, Ieyasu was sent as a hostage to the Imagawa clan. He was able to gain power and influence through his strategic alliances and was eventually able to take control of the country. He is remembered as a great leader and one of the most successful shōguns in Japanese history.

miracle777 avatar Feb 03 '23 16:02 miracle777

This doesn't seem like an issue with langchain, and can probably be closed.

dmyoung9 avatar Aug 11 '23 02:08 dmyoung9

Hi, @miracle777! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you were asking why you can only create short records when using LangChain's search tool and wanted to know how to create longer sentences like you can with the GPT-3 API. In the comments, there was a suggestion to increase the max_tokens parameter, which resolved the error you were experiencing. However, it was determined that this issue is not related to LangChain itself.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding, and please don't hesitate to reach out if you have any further questions or concerns.

dosubot[bot] avatar Nov 10 '23 16:11 dosubot[bot]