跳到内容

Salesforce

SalesforceToolSpec #

基础类:BaseToolSpec

Salesforce 工具规范。

使智能体能够使用 simple_salesforce 与 Salesforce 交互。

源代码位于 llama-index-integrations/tools/llama-index-tools-salesforce/llama_index/tools/salesforce/base.py
 4
 5
 6
 7
 8
 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
class SalesforceToolSpec(BaseToolSpec):
    """
    Salesforce tool spec.

    Gives the agent the ability to interact with Salesforce using simple_salesforce

    """

    spec_functions = ["execute_sosl", "execute_soql"]

    def __init__(self, **kargs) -> None:
        """Initialize with parameters for Salesforce connection."""
        from simple_salesforce import Salesforce

        self.sf = Salesforce(**kargs)

    def execute_sosl(self, search: str) -> str:
        """
        Returns the result of a Salesforce search as a dict decoded from
        the Salesforce response JSON payload.

        Arguments:
        * search -- the fully formatted SOSL search string, e.g.
                    `FIND {Waldo}`.

        """
        from simple_salesforce import SalesforceError

        try:
            res = self.sf.search(search)
        except SalesforceError as err:
            return f"Error running SOSL query: {err}"
        return res

    def execute_soql(self, query: str) -> str:
        """
        Returns the full set of results for the `query`. This is a
        convenience wrapper around `query(...)` and `query_more(...)`.
        The returned dict is the decoded JSON payload from the final call to
        Salesforce, but with the `totalSize` field representing the full
        number of results retrieved and the `records` list representing the
        full list of records retrieved.

        Arguments:
        * query -- the SOQL query to send to Salesforce, e.g.
                   SELECT Id FROM Lead WHERE Email = "[email protected]".

        """
        from simple_salesforce import SalesforceError

        try:
            res = self.sf.query_all(query)
        except SalesforceError as err:
            return f"Error running SOQL query: {err}"
        return res

execute_sosl #

execute_sosl(search: str) -> str

返回从 Salesforce 响应 JSON 载荷解码后的 Salesforce 搜索结果字典。

  • search -- 完整格式的 SOSL 搜索字符串,例如 FIND {Waldo}
源代码位于 llama-index-integrations/tools/llama-index-tools-salesforce/llama_index/tools/salesforce/base.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def execute_sosl(self, search: str) -> str:
    """
    Returns the result of a Salesforce search as a dict decoded from
    the Salesforce response JSON payload.

    Arguments:
    * search -- the fully formatted SOSL search string, e.g.
                `FIND {Waldo}`.

    """
    from simple_salesforce import SalesforceError

    try:
        res = self.sf.search(search)
    except SalesforceError as err:
        return f"Error running SOSL query: {err}"
    return res

execute_soql #

execute_soql(query: str) -> str

返回查询的完整结果集。这是对 query(...)query_more(...) 的便捷封装。返回的字典是从最后一次调用 Salesforce 获取并解码的 JSON 载荷,其中 totalSize 字段表示检索到的总结果数,records 列表表示检索到的完整记录列表。

  • query -- 发送到 Salesforce 的 SOQL 查询,例如 SELECT Id FROM Lead WHERE Email = "[email protected]"。
源代码位于 llama-index-integrations/tools/llama-index-tools-salesforce/llama_index/tools/salesforce/base.py
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
def execute_soql(self, query: str) -> str:
    """
    Returns the full set of results for the `query`. This is a
    convenience wrapper around `query(...)` and `query_more(...)`.
    The returned dict is the decoded JSON payload from the final call to
    Salesforce, but with the `totalSize` field representing the full
    number of results retrieved and the `records` list representing the
    full list of records retrieved.

    Arguments:
    * query -- the SOQL query to send to Salesforce, e.g.
               SELECT Id FROM Lead WHERE Email = "[email protected]".

    """
    from simple_salesforce import SalesforceError

    try:
        res = self.sf.query_all(query)
    except SalesforceError as err:
        return f"Error running SOQL query: {err}"
    return res