### Go Get App List Example Source: https://cloud.baidu.com/doc/qianfan/s/Jmh4suegh Shows how to retrieve a list of applications using the Go SDK. This example calls GetAppList with a request configuration and handles potential errors. ```Go package appbuilder apps, err := GetAppList(GetAppListRequest{ Limit: 10, }, config) if err != nil { t.Fatalf("get apps failed: %v", err) } fmt.Println(len(apps)) ``` -------------------------------- ### Java Get App List Example Source: https://cloud.baidu.com/doc/qianfan/s/Jmh4suegh Demonstrates how to fetch a list of applications using the Java SDK. This example initializes an AppList object and makes a request with a specified limit. ```Java public void GetAppsTest() throws IOException, AppBuilderServerException { AppList builder = new AppList(); AppListRequest request = new AppListRequest(); request.setLimit(10); assertNotNull(builder.getAppList(request)[0].getId()); } ``` -------------------------------- ### Install Go AppBuilder SDK Source: https://cloud.baidu.com/doc/qianfan/s/Dmh4sue98 Use this command to get the AppBuilder SDK for Go. Supports Go 1.18.1 or higher. ```shell go get github.com/baidubce/app-builder/go/appbuilder ``` -------------------------------- ### Start and Run Trace with Appbuilder SDK Source: https://cloud.baidu.com/doc/qianfan/s/qmh4suf0d Start the trace, set your AppBuilder token and App ID, create a conversation, run a query, and then end the trace. This example demonstrates basic interaction with the AppBuilder client. ```python 1# 启动trace 2import os 3import appbuilder 4 5tracer.start_trace() 6 7os.environ["APPBUILDER_TOKEN"] = "YOUR_APPBUILDER_TOKEN" 8app_id = "YOUR_APP_ID" 9 10builder = appbuilder.AppBuilderClient(app_id) 11conversation_id = builder.create_conversation() 12msg = builder.run(conversation_id=conversation_id, query="你可以做什么?",stream=True) 13 14for m in msg.content: 15 print(m) 16 17# 结束trace 18tracer.end_trace() ``` -------------------------------- ### Curl Request Example Source: https://cloud.baidu.com/doc/qianfan-api/s/4mocj9hkl An example of how to make a GET request using curl to the Get Starmap by Title API, specifying the starmap title and page number. ```curl curl -X GET "https://qianfan.baidubce.com/v2/tools/baike/starmap/get_starmap_by_title?starmap_title=节日&page=1" \ -H "Authorization: Bearer bce-v3/ALTAK-******ZftZDTn7/125eeb1c5e9ddc8cf3edf18ef6d03f1517ec9408" ``` -------------------------------- ### Start OpenClaw Service Source: https://cloud.baidu.com/doc/qianfan/s/Rmn2ms2nm Execute this command in the terminal after completing the configuration to start the OpenClaw service with daemon installation. ```Bash 1openclaw onboard --install-daemon ``` -------------------------------- ### Java Knowledgebase and Document Management Example Source: https://cloud.baidu.com/doc/qianfan/s/Umh4sue3t This comprehensive example demonstrates setting up the SDK, creating, listing, updating, and deleting knowledge bases, as well as managing documents within a knowledge base. It includes operations for getting document lists, deleting documents, creating documents from web sources, and uploading documents from files. ```Java 1public class KnowledgebaseTest { @Before public void setUp() { System.setProperty("APPBUILDER_TOKEN",""); System.setProperty("APPBUILDER_LOGLEVEL", "DEBUG"); } @Test public void testDocument() throws IOException, AppBuilderServerException { // 实例化Knowledgebase String knowledgeBaseId = ""; Knowledgebase knowledgebase = new Knowledgebase(); // 获取知识库文档列表 DocumentListRequest listRequest = new DocumentListRequest(); listRequest.setKonwledgeBaseId(knowledgeBaseId); listRequest.setLimit(10); Document[] documents = knowledgebase.getDocumentList(listRequest); // 从知识库删除文档 DocumentDeleteRequest deleteRequest = new DocumentDeleteRequest(); deleteRequest.setKonwledgeBaseId(knowledgeBaseId); deleteRequest.setDocumentId("期望删除的DocumentId"); knowledgebase.deleteDocument(deleteRequest); } @Test public void testCreateKnowledgebase() throws IOException, AppBuilderServerException { Knowledgebase knowledgebase = new Knowledgebase(); KnowledgeBaseDetail request = new KnowledgeBaseDetail(); request.setName("test_knowledgebase"); request.setDescription("test_knowledgebase"); // 创建知识库 KnowledgeBaseConfig.Index index = new KnowledgeBaseConfig.Index("public", "", "", "", ""); KnowledgeBaseConfig config = new KnowledgeBaseConfig(index); request.setConfig(config); KnowledgeBaseDetail response = knowledgebase.createKnowledgeBase(request); String knowledgeBaseId = response.getId(); System.out.println(knowledgeBaseId); assertNotNull(response.getId()); // 获取知识库详情 KnowledgeBaseDetail detail = knowledgebase.getKnowledgeBaseDetail(knowledgeBaseId); System.out.println(detail.getId()); assertNotNull(detail.getId()); // 获取知识库列表 KnowledgeBaseListRequest listRequest = new KnowledgeBaseListRequest(knowledgeBaseId, 10, null); KnowledgeBaseListResponse knowledgeBases = knowledgebase.getKnowledgeBaseList(listRequest); System.out.println(knowledgeBases.getMarker()); assertNotNull(knowledgeBases.getMarker()); // 更新知识库 KnowledgeBaseModifyRequest modifyRequest = new KnowledgeBaseModifyRequest(); modifyRequest.setKnowledgeBaseId(knowledgeBaseId); modifyRequest.setName("test_knowledgebase2"); modifyRequest.setDescription(knowledgeBaseId); knowledgebase.modifyKnowledgeBase(modifyRequest); // 导入知识库 DocumentsCreateRequest.Source source = new DocumentsCreateRequest.Source("web", new String[] {"https://baijiahao.baidu.com/s?id=1802527379394162441"}, 1); DocumentsCreateRequest.ProcessOption.Parser parser = new DocumentsCreateRequest.ProcessOption.Parser( new String[] {"layoutAnalysis", "ocr"}); DocumentsCreateRequest.ProcessOption.Chunker.Separator separator = new DocumentsCreateRequest.ProcessOption.Chunker.Separator(new String[] {"。"}, 300, 0.25); DocumentsCreateRequest.ProcessOption.Chunker chunker = new DocumentsCreateRequest.ProcessOption.Chunker(new String[] {"separator"}, separator, null, new String[] {"title", "filename"}); DocumentsCreateRequest.ProcessOption.KnowledgeAugmentation knowledgeAugmentation = new DocumentsCreateRequest.ProcessOption.KnowledgeAugmentation( new String[] {"faq"}); DocumentsCreateRequest.ProcessOption processOption = new DocumentsCreateRequest.ProcessOption("custom", parser, chunker, knowledgeAugmentation); DocumentsCreateRequest documentsCreateRequest = new DocumentsCreateRequest(knowledgeBaseId, "rawText", source, processOption); knowledgebase.createDocuments(documentsCreateRequest); // 上传文档 String filePath = "src/test/java/com/baidubce/appbuilder/files/test.pdf"; DocumentsCreateRequest.Source source2 = new DocumentsCreateRequest.Source("file", null, null); DocumentsCreateRequest documentsCreateRequest2 = new DocumentsCreateRequest(knowledgeBaseId, "rawText", source2, processOption); knowledgebase.uploadDocuments(filePath, documentsCreateRequest2); // 删除知识库 knowledgebase.deleteKnowledgeBase(knowledgeBaseId); } @Test public void testCreateChunk() throws IOException, AppBuilderServerException { String documentId = ""; // 知识库ID String knowledgeBaseId = ""; // Appbuilder Token ``` -------------------------------- ### cURL Request Example Source: https://cloud.baidu.com/doc/qianfan-api/s/Bmi6vu310 An example using cURL to make a GET request to the file content endpoint. Ensure you replace API_KEY with your actual key. ```curl curl -X GET https://qianfan.baidubce.com/v2/files/file-abc123/content \ --H "Authorization: Bearer API_KEY" ``` -------------------------------- ### Connect to VectorDB CLI (Example) Source: https://cloud.baidu.com/doc/qianfan-docs/s/im8qt6bqz Example of connecting to a VectorDB instance with a specified user and endpoint. ```shell ./vectordb-cli -u root -e http://127.0.0.1:5287 ``` -------------------------------- ### Example API Request with Authorization Header Source: https://cloud.baidu.com/doc/qianfan-api/s/Zm9lc22hr This example demonstrates how to construct a GET request to the password API, including the necessary Authorization header with a generated signature. ```shell curl --location 'http://vdb.bj.baidubce.com/v1/vdb/account/password?instanceId=vdb-bj-WrBboKEYhHMx&username=root' \ --header 'Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2017-11-21T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Example API Request with Authorization Header Source: https://cloud.baidu.com/doc/qianfan-api/s/Qm9lc22ff This example demonstrates how to make a GET request to the /v1/vdb/account/list endpoint, including the necessary Authorization header with a generated signature. ```shell curl --location 'http://vdb.bj.baidubce.com/v1/vdb/account/list?instanceId=vdb-bj-WrBboKEYhHMx' \ --header 'Authorization: bce-auth-v1/f81d3b34e48048fbb2634dc7882d7e21/2017-11-21T04:17:29Z/3600/host/74c506f68c65e26c633bfa104c863fffac5190fdec1ec24b7c03eb5d67d2e1de' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Initialize MochowClient and Database Source: https://cloud.baidu.com/doc/qianfan-docs/s/Bm8qt6cal Reads database configuration, initializes the MochowClient, and selects or creates a database. ```python config_obj = Configuration(credentials=config.credentials, endpoint=config.endpoint) client = pymochow.MochowClient(config_obj) db = client.database("document") ``` -------------------------------- ### Get Livelihood Trending List Source: https://cloud.baidu.com/doc/qianfan/s/fmmacsm17 Example of how to make a GET request to retrieve the livelihood trending list from the Baidu Trending API. Ensure you include the Authorization header. ```shell curl --request GET \ --url 'https://qianfan.baidubce.com/v2/tools/baidu_trending?tab=livelihood' \ --header 'Authorization: Bearer xxxxxx' ``` -------------------------------- ### Create Service Request Example Source: https://cloud.baidu.com/doc/qianfan/s/6mh4sv4pc This snippet shows a sample POST request to create a new service, including model details, service name, and deployment configuration. ```bash POST /v2/service?Action=CreateService HTTP/1.1 Host: qianfan.baidubce.com Authorization: authorization string Content-Type: application/json { "modelSetId": "am-3aa2***5c9", "modelId": "amv-ur1u1***722s", "name": "apitest_1226_3", "urlSuffix": "apitest_1226_3", "deploymentConfig": { "qps": 1, "replicaComputeUnitCount": 1, "replicasCount":1, "deploymentComputeUnitList": [ { "instanceId": "unit-gdqb1Fot", "deploymentReplicasCount": 2 } ] }, "protocolVersion": 1 } ``` -------------------------------- ### List Files with Query Parameters Source: https://cloud.baidu.com/doc/qianfan-api/s/Tmi74q65f Demonstrates how to list files using query parameters like purpose, limit, and order. Ensure your Authorization header is correctly set. ```shell curl "https://qianfan.baidubce.com/v2/files?purpose=fine-tune&limit=3&order=desc" \ -H "Authorization: Bearer bce-v3/ALTAK-*********/614fb**********" ``` -------------------------------- ### Get Trending Lists Request Source: https://cloud.baidu.com/doc/qianfan/s/Amhcvzqs0 Example of how to make a GET request to the Trending Lists API to fetch trending data. Ensure you replace '******' with your actual Bearer token. ```shell curl --location --request GET \ "https://qianfan.baidubce.com/v2/tools/trending_lists/medium?type=6" \ --header 'Authorization: Bearer ******' ``` -------------------------------- ### Create OpenCode Configuration Directory Source: https://cloud.baidu.com/doc/qianfan/s/Pmov9osdg Navigate to the OpenCode configuration directory and create the 'opencode.json' file. The path varies by operating system. ```bash # Navigate to the directory # macOS, Linux ~/.config/opencode # Windows C:\Users\YourUsername\.config\opencode\ # Create opencode.json file # macOS, Linux touch opencode.json ``` -------------------------------- ### Create Service with Pre-purchased Resources Source: https://cloud.baidu.com/doc/qianfan/s/6mh4sv4pc This example demonstrates how to call the CreateService API to provision a service using already purchased resources. It includes details on model selection and deployment configuration. ```APIDOC ## POST /v2/service?Action=CreateService ### Description Provisions a new service using pre-purchased resources. This is suitable when you have existing resource allocations available. ### Method POST ### Endpoint https://qianfan.baidubce.com/v2/service?Action=CreateService ### Parameters #### Request Body - **modelSetId** (string) - Required - The ID of the model set to use. - **modelId** (string) - Required - The ID of the model to deploy. - **name** (string) - Required - The name of the service. - **urlSuffix** (string) - Required - A unique suffix for the service URL. - **deploymentConfig** (object) - Required - Configuration for deploying the service. - **qps** (integer) - Required - Queries per second limit. - **replicaComputeUnitCount** (integer) - Required - Number of compute units per replica. - **replicasCount** (integer) - Required - Number of replicas. - **deploymentComputeUnitList** (array) - Required - List of compute units for deployment. - **instanceId** (string) - Required - The ID of the compute instance. - **deploymentReplicasCount** (integer) - Required - Number of replicas for this compute unit. - **protocolVersion** (integer) - Required - The protocol version to use. ### Request Example ```json { "modelSetId": "am-3aa2***5c9", "modelId": "amv-ur1u1***722s", "name": "apitest_1226_3", "urlSuffix": "apitest_1226_3", "deploymentConfig": { "qps": 1, "replicaComputeUnitCount": 1, "replicasCount":1, "deploymentComputeUnitList": [ { "instanceId": "unit-gdqb1Fot", "deploymentReplicasCount": 2 } ] }, "protocolVersion": 1 } ``` ### Response #### Success Response (200) - **requestId** (string) - The ID of the request. - **result** (object) - The result of the operation. - **serviceId** (string) - The ID of the created service. #### Response Example ```json { "requestId": "18a7c588-7157-4184-b911-e4ccfe5f719b", "result": { "serviceId": "svco-juw***j1" } } ``` ``` -------------------------------- ### Create New Console Project and Add OpenAI Package Source: https://cloud.baidu.com/doc/qianfan-docs/s/mm9l6occh This snippet shows how to set up a new .NET console project and add the necessary OpenAI package, including the prerelease flag. ```.NET 1# 创建新控制台项目(若已有项目可跳过) 2dotnet new console -n MyOpenAIProject 3cd MyOpenAIProject 4 5# 添加OpenAI包(需--prerelease参数,因当前包为预发布版) 6dotnet add package OpenAI --prerelease ```