Skip to content

Valyu

ValyuToolSpec #

Bases: BaseToolSpec

Valyu tool spec.

Source code in llama-index-integrations/tools/llama-index-tools-valyu/llama_index/tools/valyu/base.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class ValyuToolSpec(BaseToolSpec):
    """Valyu tool spec."""

    spec_functions = [
        "context",
    ]

    def __init__(
        self,
        api_key: str,
        verbose: bool = False,
        max_price: Optional[float] = 100,
    ) -> None:
        """Initialize with parameters."""
        from valyu import Valyu

        self.client = Valyu(api_key=api_key)
        self._verbose = verbose
        self._max_price = max_price

    def context(
        self,
        query: str,
        search_type: str = "both",
        data_sources: Optional[List[str]] = None,
        max_num_results: int = 10,
        max_price: Optional[float] = None,
        query_rewrite: bool = True,
        similarity_threshold: float = 0.5,
    ) -> List[Document]:
        """Find relevant programmaticly licensed proprietary content and the web to answer your query.

        Args:
            query (str): The question or topic to search for
            search_type (str): Type of sources to search - "proprietary", "web", or "both"
            data_sources (Optional[List[str]]): Specific indexes to query from
            max_num_results (int): Maximum number of results to return. Defaults to 10
            max_price (Optional[float]): Maximum price per content in PCM. Defaults to 100
            query_rewrite (bool): Whether to rewrite the query to improve results. Defaults to True
            similarity_threshold (float): Minimum similarity score for results. Defaults to 0.5

        Returns:
            List[Document]: List of Document objects containing the search results
        """
        if max_price is None:
            max_price = self._max_price

        response = self.client.context(
            query=query,
            search_type=search_type,
            data_sources=data_sources,
            max_num_results=max_num_results,
            max_price=max_price,
            query_rewrite=query_rewrite,
            similarity_threshold=similarity_threshold,
        )

        if self._verbose:
            print(f"[Valyu Tool] Response: {response}")

        return [
            Document(
                text=result.content,
                metadata={
                    "title": result.title,
                    "url": result.url,
                    "source": result.source,
                    "price": result.price,
                },
            )
            for result in response.results
        ]

context #

context(query: str, search_type: str = 'both', data_sources: Optional[List[str]] = None, max_num_results: int = 10, max_price: Optional[float] = None, query_rewrite: bool = True, similarity_threshold: float = 0.5) -> List[Document]

Find relevant programmaticly licensed proprietary content and the web to answer your query.

Parameters:

Name Type Description Default
query str

The question or topic to search for

required
search_type str

Type of sources to search - "proprietary", "web", or "both"

'both'
data_sources Optional[List[str]]

Specific indexes to query from

None
max_num_results int

Maximum number of results to return. Defaults to 10

10
max_price Optional[float]

Maximum price per content in PCM. Defaults to 100

None
query_rewrite bool

Whether to rewrite the query to improve results. Defaults to True

True
similarity_threshold float

Minimum similarity score for results. Defaults to 0.5

0.5

Returns:

Type Description
List[Document]

List[Document]: List of Document objects containing the search results

Source code in llama-index-integrations/tools/llama-index-tools-valyu/llama_index/tools/valyu/base.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def context(
    self,
    query: str,
    search_type: str = "both",
    data_sources: Optional[List[str]] = None,
    max_num_results: int = 10,
    max_price: Optional[float] = None,
    query_rewrite: bool = True,
    similarity_threshold: float = 0.5,
) -> List[Document]:
    """Find relevant programmaticly licensed proprietary content and the web to answer your query.

    Args:
        query (str): The question or topic to search for
        search_type (str): Type of sources to search - "proprietary", "web", or "both"
        data_sources (Optional[List[str]]): Specific indexes to query from
        max_num_results (int): Maximum number of results to return. Defaults to 10
        max_price (Optional[float]): Maximum price per content in PCM. Defaults to 100
        query_rewrite (bool): Whether to rewrite the query to improve results. Defaults to True
        similarity_threshold (float): Minimum similarity score for results. Defaults to 0.5

    Returns:
        List[Document]: List of Document objects containing the search results
    """
    if max_price is None:
        max_price = self._max_price

    response = self.client.context(
        query=query,
        search_type=search_type,
        data_sources=data_sources,
        max_num_results=max_num_results,
        max_price=max_price,
        query_rewrite=query_rewrite,
        similarity_threshold=similarity_threshold,
    )

    if self._verbose:
        print(f"[Valyu Tool] Response: {response}")

    return [
        Document(
            text=result.content,
            metadata={
                "title": result.title,
                "url": result.url,
                "source": result.source,
                "price": result.price,
            },
        )
        for result in response.results
    ]