llama-index-llms-openai 0.1.30__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,7 +166,8 @@ class OpenAI(FunctionCallingLLM):
166
166
  gt=0,
167
167
  )
168
168
  logprobs: Optional[bool] = Field(
169
- description="Whether to return logprobs per token."
169
+ description="Whether to return logprobs per token.",
170
+ default=None,
170
171
  )
171
172
  top_logprobs: int = Field(
172
173
  description="The number of top token log probs to return.",
@@ -187,7 +188,7 @@ class OpenAI(FunctionCallingLLM):
187
188
  description="The timeout, in seconds, for API requests.",
188
189
  gte=0,
189
190
  )
190
- default_headers: Dict[str, str] = Field(
191
+ default_headers: Optional[Dict[str, str]] = Field(
191
192
  default=None, description="The default headers for API requests."
192
193
  )
193
194
  reuse_client: bool = Field(
@@ -390,7 +391,13 @@ class OpenAI(FunctionCallingLLM):
390
391
  base_kwargs["top_logprobs"] = self.top_logprobs
391
392
  else:
392
393
  base_kwargs["logprobs"] = self.top_logprobs # int in this case
393
- return {**base_kwargs, **self.additional_kwargs}
394
+
395
+ # can't send stream_options to the API when not streaming
396
+ all_kwargs = {**base_kwargs, **self.additional_kwargs}
397
+ if "stream" not in all_kwargs and "stream_options" in all_kwargs:
398
+ del all_kwargs["stream_options"]
399
+
400
+ return all_kwargs
394
401
 
395
402
  @llm_retry_decorator
396
403
  def _chat(self, messages: Sequence[ChatMessage], **kwargs: Any) -> ChatResponse:
@@ -486,8 +493,7 @@ class OpenAI(FunctionCallingLLM):
486
493
  is_function = False
487
494
  for response in client.chat.completions.create(
488
495
  messages=message_dicts,
489
- stream=True,
490
- **self._get_model_kwargs(**kwargs),
496
+ **self._get_model_kwargs(stream=True, **kwargs),
491
497
  ):
492
498
  response = cast(ChatCompletionChunk, response)
493
499
  if len(response.choices) > 0:
@@ -561,15 +567,14 @@ class OpenAI(FunctionCallingLLM):
561
567
  @llm_retry_decorator
562
568
  def _stream_complete(self, prompt: str, **kwargs: Any) -> CompletionResponseGen:
563
569
  client = self._get_client()
564
- all_kwargs = self._get_model_kwargs(**kwargs)
570
+ all_kwargs = self._get_model_kwargs(stream=True, **kwargs)
565
571
  self._update_max_tokens(all_kwargs, prompt)
566
572
 
567
573
  def gen() -> CompletionResponseGen:
568
574
  text = ""
569
575
  for response in client.completions.create(
570
576
  prompt=prompt,
571
- stream=True,
572
- **all_kwargs,
577
+ **kwargs,
573
578
  ):
574
579
  if len(response.choices) > 0:
575
580
  delta = response.choices[0].text
@@ -728,8 +733,7 @@ class OpenAI(FunctionCallingLLM):
728
733
  first_chat_chunk = True
729
734
  async for response in await aclient.chat.completions.create(
730
735
  messages=message_dicts,
731
- stream=True,
732
- **self._get_model_kwargs(**kwargs),
736
+ **self._get_model_kwargs(stream=True, **kwargs),
733
737
  ):
734
738
  response = cast(ChatCompletionChunk, response)
735
739
  if len(response.choices) > 0:
@@ -815,14 +819,13 @@ class OpenAI(FunctionCallingLLM):
815
819
  self, prompt: str, **kwargs: Any
816
820
  ) -> CompletionResponseAsyncGen:
817
821
  aclient = self._get_aclient()
818
- all_kwargs = self._get_model_kwargs(**kwargs)
822
+ all_kwargs = self._get_model_kwargs(stream=True, **kwargs)
819
823
  self._update_max_tokens(all_kwargs, prompt)
820
824
 
821
825
  async def gen() -> CompletionResponseAsyncGen:
822
826
  text = ""
823
827
  async for response in await aclient.completions.create(
824
828
  prompt=prompt,
825
- stream=True,
826
829
  **all_kwargs,
827
830
  ):
828
831
  if len(response.choices) > 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: llama-index-llms-openai
3
- Version: 0.1.30
3
+ Version: 0.2.0
4
4
  Summary: llama-index llms openai integration
5
5
  License: MIT
6
6
  Author: llama-index
@@ -11,7 +11,7 @@ Classifier: Programming Language :: Python :: 3.9
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
- Requires-Dist: llama-index-core (>=0.10.57,<0.11.0)
14
+ Requires-Dist: llama-index-core (>=0.11.0,<0.12.0)
15
15
  Requires-Dist: openai (>=1.40.0,<2.0.0)
16
16
  Description-Content-Type: text/markdown
17
17
 
@@ -0,0 +1,6 @@
1
+ llama_index/llms/openai/__init__.py,sha256=vm3cIBSGkBFlE77GyfyN0EhpJcnJZN95QMhPN53EkbE,148
2
+ llama_index/llms/openai/base.py,sha256=dbL-ikXVEnUsOc25TWyOfrct4EY1EiiiEJPX7W4TDJI,34060
3
+ llama_index/llms/openai/utils.py,sha256=VuDXkLR_BGVqoZc9IJqiJlVloZwG9Z7s1nGPAhlbvWE,13079
4
+ llama_index_llms_openai-0.2.0.dist-info/METADATA,sha256=DLpR9roOxghLKrvnI8w_uyX4YGCefqulRcFnXpd-cqY,648
5
+ llama_index_llms_openai-0.2.0.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
6
+ llama_index_llms_openai-0.2.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.8.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,6 +0,0 @@
1
- llama_index/llms/openai/__init__.py,sha256=vm3cIBSGkBFlE77GyfyN0EhpJcnJZN95QMhPN53EkbE,148
2
- llama_index/llms/openai/base.py,sha256=j-BiZ9E3pFG2RDSP8Vq75SHfZCId9XU5ymAddBF8x8I,33876
3
- llama_index/llms/openai/utils.py,sha256=VuDXkLR_BGVqoZc9IJqiJlVloZwG9Z7s1nGPAhlbvWE,13079
4
- llama_index_llms_openai-0.1.30.dist-info/METADATA,sha256=VnG5MXkR-ZUoxou8H9tUsy1uY8zGoC578GUG0Dx5Eoc,650
5
- llama_index_llms_openai-0.1.30.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
- llama_index_llms_openai-0.1.30.dist-info/RECORD,,