Skip to content

Issue reproducing the example in Readme  #65

Closed

Description

@tranhoangnguyen03
from sglang import function, system, user, assistant, gen, set_default_backend, OpenAI

@function
def multi_turn_question(s, question_1, question_2):
    s += system("You are a helpful assistant.")
    s += user(question_1)
    s += assistant(gen("answer_1", max_tokens=256))
    s += user(question_2)
    s += assistant(gen("answer_2", max_tokens=256))

set_default_backend(OpenAI("gpt-3.5-turbo"))

state = multi_turn_question.run(
    question_1="What is the capital of the United States?",
    question_2="List two local attractions.",
)

for m in state.messages():
    print(m["role"], ":", m["content"])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-3-ac9af75fa374>](https://localhost:8080/#) in <cell line: 11>()
      9     s += assistant(gen("answer_2", max_tokens=256))
     10 
---> 11 set_default_backend(OpenAI("gpt-3.5-turbo"))
     12 
     13 state = multi_turn_question.run(

[/usr/local/lib/python3.10/dist-packages/sglang/backend/openai.py](https://localhost:8080/#) in __init__(self, model_name, *args, **kwargs)
     52     def __init__(self, model_name, *args, **kwargs):
     53         super().__init__()
---> 54         self.client = openai.OpenAI(*args, **kwargs)
     55 
     56         if isinstance(openai, Exception):

AttributeError: 'ModuleNotFoundError' object has no attribute 'OpenAI'

Activity

  1. merrymercy commented on Jan 21, 2024

    @merrymercy
    Collaborator

    please install this openai package https://github.com/openai/openai-python

  2. added a commit that references this issue on Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions