Skip to content

Commit

Permalink
Loading the default service_context in SubQuestionQueryEngine (#9760)
Browse files Browse the repository at this point in the history
* Loading the default service_context in SubQuestionQueryEngine

* cr

---------

Co-authored-by: Haotian Zhang <[email protected]>
  • Loading branch information
Kirushikesh and hatianzhang authored Dec 30, 2023
1 parent 8a6c3ac commit 3b52215
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions llama_index/query_engine/sub_question_query_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,18 @@ def from_defaults(
elif len(query_engine_tools) > 0:
callback_manager = query_engine_tools[0].query_engine.callback_manager

service_context = service_context or ServiceContext.from_defaults()
if question_gen is None:
if service_context is None:
# use default openai model that supports function calling API
question_gen = OpenAIQuestionGenerator.from_defaults()
else:
# try to use OpenAI function calling based question generator.
# if incompatible, use general LLM question generator
try:
question_gen = OpenAIQuestionGenerator.from_defaults(
llm=service_context.llm
)
except ValueError:
question_gen = LLMQuestionGenerator.from_defaults(
service_context=service_context
)
# try to use OpenAI function calling based question generator.
# if incompatible, use general LLM question generator
try:
question_gen = OpenAIQuestionGenerator.from_defaults(
llm=service_context.llm
)
except ValueError:
question_gen = LLMQuestionGenerator.from_defaults(
service_context=service_context
)

synth = response_synthesizer or get_response_synthesizer(
callback_manager=callback_manager,
Expand Down

0 comments on commit 3b52215

Please sign in to comment.