-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add reranker & proxy example (#564)
- Loading branch information
Showing
4 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
java/example/src/main/java/com/baidubce/HttpProxyExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.baidubce; | ||
|
||
import com.baidubce.qianfan.Qianfan; | ||
import com.baidubce.qianfan.model.chat.ChatResponse; | ||
|
||
/** | ||
* 本示例通过设置系统代理,实现了SDK的请求通过代理服务器发送 | ||
*/ | ||
public class HttpProxyExample { | ||
public static void main(String[] args) { | ||
System.setProperty("https.proxyHost", "127.0.0.1"); | ||
System.setProperty("https.proxyPort", "7890"); | ||
Qianfan qianfan = new Qianfan(); | ||
ChatResponse response = qianfan.chatCompletion() | ||
.addMessage("user", "你好!我正在通过代理与你聊天哦") | ||
.execute(); | ||
System.out.println(response.getResult()); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
java/example/src/main/java/com/baidubce/RerankExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.baidubce; | ||
|
||
import com.baidubce.qianfan.Qianfan; | ||
import com.baidubce.qianfan.model.rerank.RerankResponse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* 本示例实现了Reranker调用流程,对于给定的Query和文档列表进行重排序,将更相关的文档排在前面 | ||
*/ | ||
public class RerankExample { | ||
public static void main(String[] args) { | ||
List<String> documents = new ArrayList<>(); | ||
documents.add("上海位于中国东部海岸线的中心,长江三角洲最东部。"); | ||
documents.add("上海现在的温度是27度。"); | ||
documents.add("深圳现在的温度是29度。"); | ||
|
||
RerankResponse response = new Qianfan().rerank() | ||
.query("上海现在气温多少?") | ||
.documents(documents) | ||
.execute(); | ||
response.getResults().forEach(data -> { | ||
System.out.println(data.getDocument()); | ||
System.out.println(data.getRelevanceScore()); | ||
}); | ||
} | ||
} |