exa-py 1.8.6__tar.gz → 1.8.7__tar.gz

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.

Potentially problematic release.


This version of exa-py might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: exa-py
3
- Version: 1.8.6
3
+ Version: 1.8.7
4
4
  Summary: Python SDK for Exa API.
5
5
  Author: Exa AI
6
6
  Author-email: hello@exa.ai
@@ -505,7 +505,7 @@ class ResultWithTextAndHighlightsAndSummary(_Result):
505
505
 
506
506
  @dataclass
507
507
  class AnswerResult:
508
- """A class representing a source result for an answer.
508
+ """A class representing a result for an answer.
509
509
 
510
510
  Attributes:
511
511
  title (str): The title of the search result.
@@ -513,21 +513,21 @@ class AnswerResult:
513
513
  id (str): The temporary ID for the document.
514
514
  published_date (str, optional): An estimate of the creation date, from parsing HTML content.
515
515
  author (str, optional): If available, the author of the content.
516
+ text (str, optional): The full page text from each search result.
516
517
  """
517
-
518
+ id: str
518
519
  url: str
519
- id: str
520
520
  title: Optional[str] = None
521
- author: Optional[str] = None
522
521
  published_date: Optional[str] = None
522
+ author: Optional[str] = None
523
523
  text: Optional[str] = None
524
524
 
525
525
  def __init__(self, **kwargs):
526
- self.url = kwargs['url']
527
526
  self.id = kwargs['id']
528
- self.title = kwargs.get('title')
529
- self.author = kwargs.get('author')
527
+ self.url = kwargs['url']
528
+ self.title = kwargs.get('title')
530
529
  self.published_date = kwargs.get('published_date')
530
+ self.author = kwargs.get('author')
531
531
  self.text = kwargs.get('text')
532
532
 
533
533
  def __str__(self):
@@ -546,23 +546,23 @@ class StreamChunk:
546
546
 
547
547
  Attributes:
548
548
  content (Optional[str]): The partial text content of the answer
549
- sources (Optional[List[AnswerResult]]): List of sources if provided in this chunk
549
+ citations (Optional[List[AnswerResult]]): List of citations if provided in this chunk
550
550
  """
551
551
  content: Optional[str] = None
552
- sources: Optional[List[AnswerResult]] = None
552
+ citations: Optional[List[AnswerResult]] = None
553
553
 
554
554
  def has_data(self) -> bool:
555
555
  """Check if this chunk contains any data."""
556
- return self.content is not None or self.sources is not None
556
+ return self.content is not None or self.citations is not None
557
557
 
558
558
  def __str__(self) -> str:
559
559
  """Format the chunk data as a string."""
560
560
  output = ""
561
561
  if self.content:
562
562
  output += self.content
563
- if self.sources:
564
- output += "\nSources:"
565
- for source in self.sources:
563
+ if self.citations:
564
+ output += "\nCitations:"
565
+ for source in self.citations:
566
566
  output += f"\n{source}"
567
567
  return output
568
568
 
@@ -573,21 +573,21 @@ class AnswerResponse:
573
573
 
574
574
  Attributes:
575
575
  answer (str): The generated answer.
576
- sources (List[AnswerResult]): A list of sources used to generate the answer.
576
+ citations (List[AnswerResult]): A list of citations used to generate the answer.
577
577
  """
578
578
 
579
579
  answer: str
580
- sources: List[AnswerResult]
580
+ citations: List[AnswerResult]
581
581
 
582
582
  def __str__(self):
583
- output = f"Answer: {self.answer}\n\nSources:"
584
- for source in self.sources:
583
+ output = f"Answer: {self.answer}\n\nCitations:"
584
+ for source in self.citations:
585
585
  output += f"\nTitle: {source.title}"
586
+ output += f"\nID: {source.id}"
586
587
  output += f"\nURL: {source.url}"
587
- output += f"\nPublished: {source.published_date}"
588
+ output += f"\nPublished Date: {source.published_date}"
588
589
  output += f"\nAuthor: {source.author}"
589
- if source.text:
590
- output += f"\nText: {source.text}"
590
+ output += f"\nText: {source.text}"
591
591
  output += "\n"
592
592
  return output
593
593
 
@@ -615,16 +615,16 @@ class StreamAnswerResponse:
615
615
  continue
616
616
 
617
617
  content = None
618
- sources = None
618
+ citations = None
619
619
 
620
620
  if "choices" in chunk and chunk["choices"]:
621
621
  if "delta" in chunk["choices"][0]:
622
622
  content = chunk["choices"][0]["delta"].get("content")
623
623
 
624
- if "sources" in chunk and chunk["sources"] and chunk["sources"] != "null":
625
- sources = [AnswerResult(**to_snake_case(s)) for s in chunk["sources"]]
624
+ if "citations" in chunk and chunk["citations"] and chunk["citations"] != "null":
625
+ citations = [AnswerResult(**to_snake_case(s)) for s in chunk["citations"]]
626
626
 
627
- stream_chunk = StreamChunk(content=content, sources=sources)
627
+ stream_chunk = StreamChunk(content=content, citations=citations)
628
628
  if stream_chunk.has_data():
629
629
  yield stream_chunk
630
630
 
@@ -686,7 +686,7 @@ class Exa:
686
686
  self,
687
687
  api_key: Optional[str],
688
688
  base_url: str = "https://api.exa.ai",
689
- user_agent: str = "exa-py 1.8.6",
689
+ user_agent: str = "exa-py 1.8.7",
690
690
  ):
691
691
  """Initialize the Exa client with the provided API key and optional base URL and user agent.
692
692
 
@@ -1673,7 +1673,7 @@ class Exa:
1673
1673
  text (bool, optional): Whether to include full text in the results. Defaults to False.
1674
1674
 
1675
1675
  Returns:
1676
- AnswerResponse: An object containing the answer and sources.
1676
+ AnswerResponse: An object containing the answer and citations.
1677
1677
 
1678
1678
  Raises:
1679
1679
  ValueError: If stream=True is provided. Use stream_answer() instead for streaming responses.
@@ -1694,7 +1694,7 @@ class Exa:
1694
1694
 
1695
1695
  return AnswerResponse(
1696
1696
  response["answer"],
1697
- [AnswerResult(**to_snake_case(result)) for result in response["sources"]]
1697
+ [AnswerResult(**to_snake_case(result)) for result in response["citations"]]
1698
1698
  )
1699
1699
 
1700
1700
  def stream_answer(
@@ -1710,7 +1710,7 @@ class Exa:
1710
1710
  text (bool): Whether to include full text in the results. Defaults to False.
1711
1711
 
1712
1712
  Returns:
1713
- StreamAnswerResponse: An object that can be iterated over to retrieve (partial text, partial sources).
1713
+ StreamAnswerResponse: An object that can be iterated over to retrieve (partial text, partial citations).
1714
1714
  Each iteration yields a tuple of (Optional[str], Optional[List[AnswerResult]]).
1715
1715
  """
1716
1716
  options = {
@@ -0,0 +1,11 @@
1
+ from exa_py import Exa
2
+
3
+ exa = Exa(api_key = "995da727-7b91-42d0-b282-326daa290b39")
4
+
5
+ response = exa.stream_answer(
6
+ "How close are we to meeting aliens?",
7
+ text=True
8
+ )
9
+
10
+ for chunk in response:
11
+ print(chunk, end='', flush=True)
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "exa-py"
3
- version = "1.8.6"
3
+ version = "1.8.7"
4
4
  description = "Python SDK for Exa API."
5
5
  authors = ["Exa AI <hello@exa.ai>"]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes