guidance icon indicating copy to clipboard operation
guidance copied to clipboard

Basic example with davinci saying role_start() can only be used in chat mode

Open RonanKMcGovern opened this issue 2 years ago • 1 comments

The bug Assertion Error: role_start() can only be used in chat mode

To Reproduce

import guidance
import openai

import os
from dotenv import load_dotenv

# Load .env file. The path may be different based on your setup.
load_dotenv()

# Now you can use os.getenv to get the values from .env file
openai.organization = os.getenv("YOUR_ORG_ID")
openai.api_key = os.getenv("OPENAI_API_KEY")

openai.Model.list()

# connect to a chat model like GPT-4 or Vicuna
davinci = guidance.llms.OpenAI("text-davinci-003")
# vicuna = guidance.llms.transformers.Vicuna("your_path/vicuna_13B", device_map="auto")

experts = guidance('''
{{#system~}}
You are a helpful and terse assistant.
{{~/system}}

{{#user~}}
I want a response to the following question:
{{query}}
Name 3 world-class experts (past or present) who would be great at answering this?
Don't answer the question yet.
{{~/user}}

{{#assistant~}}
{{gen 'expert_names' temperature=0 max_tokens=300}}
{{~/assistant}}

{{#user~}}
Great, now please answer the question as if these experts had collaborated in writing a joint anonymous answer.
{{~/user}}

{{#assistant~}}
{{gen 'answer' temperature=0 max_tokens=500}}
{{~/assistant}}
''', llm=davinci)

experts(query='How can I be more productive?')

System info (please complete the following information):

  • OS (e.g. Ubuntu, Windows 11, Mac OS, etc.): MacOS M1 silicon.
  • Guidance Version (guidance.__version__): 0.0.61

RonanKMcGovern avatar Jun 05 '23 21:06 RonanKMcGovern

text-davinci doesn't support chat mode, you would need to use gpt-3.5 turbo or gpt-4

chiragshah285 avatar Jun 05 '23 21:06 chiragshah285

Unfortunately, for me, gpt-3.5 and gpt-4 doesn't recognize the role tags anymore. Does anyone else have the same problem?

akfhsueh avatar Oct 02 '23 02:10 akfhsueh

We tested the new release with chat models from OpenAI, so hopefully it works now :)

marcotcr avatar Nov 14 '23 21:11 marcotcr