Comments (9)
当然可以!我正打算加入多个接口选择,目前的加入顺序是:
- Bing
当然如果你想帮助我完成其他接口的接入,我预留了接口在 src/Youdao/ITranslater.cs ,可以很方便接入一个新的翻译引擎!
from powertranslator.
当然可以!我正打算加入多个接口选择,目前的加入顺序是:
- Google 谷歌
- Bing 必应
当然如果你想帮助我完成其他接口的接入,我预留了接口在 src/Youdao/ITranslater.cs ,可以很方便接入一个新的翻译引擎!
感谢!可惜我心有余而力不足,并不了解相关内容,恐怕很难向您提供有益的帮助。
另外我在使用过程中发现一个点,使用 Ctrl + Enter 进行朗读时直接关闭了 PT,但是朗读这个功能并不适合立刻关闭 PT 吧?当然只是我个人的看法,如果有方法可供调整我认为就更好了。
from powertranslator.
对,之前我也发现了这个问题,按道理确实不应该关,我在代码里的实现也是朗读不关PT,但是好像不论我是否设置他关闭,只要有enter
按下,始终都会关闭,我会在后面持续关注这个问题!
from powertranslator.
对,之前我也发现了这个问题,按道理确实不应该关,我在代码里的实现也是朗读不关PT,但是好像不论我是否设置他关闭,只要有
enter
按下,始终都会关闭,我会在后面持续关注这个问题!
好的,再次感谢,期待插件的后续更新!
from powertranslator.
期待添加google翻译
from powertranslator.
提供Azure的ChatGPT的对接方式参考,这两家本质上一样,Azure多了一些请求头,以及自定义API地址,但它们返回和请求结构都一样的,但好在微软搞了SDK,C#写起来结构简约些。
也可以不用自己开发那么多,统一使用OPENAI的API,但提供自定义URL的方式。然后用户可以通过使用https://github.com/songquanpeng/one-api
等类似项目自行适配。
提示词可以通过一个文件配置配置提示词,纯示范:
===
Author: N0I0C0K
Name: "PowerTranslator"
Version: 0.01
===
你是一个翻译器。我会输入任何一种语言,你会通过如下的结构告知我{英语}的翻译结果,并给出不超过15个字的使用示范。如果有多个对应的翻译结果,可以在list中依次添加。最终使用统一的JSON结构回复,不需要除JSON以外的内容。
{
"翻译结果": [],
"属性": [
{
"词性": "",
"词根": "",
"含义": ""
}
]
}
// API客户端工厂接口
public interface IApiClientFactory
{
IApiClient CreateClient();
}
// API客户端接口
public interface IApiClient
{
string GetResponse(string prompt);
}
using Azure;
using Azure.AI.OpenAI;
using System;
// Azure 客户端实现
public class AzureOpenAIClient : IApiClient
{
private OpenAIClient _client;
public AzureOpenAIClient(string endpoint, string key)
{
_client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key));
}
// 实现获取响应的方法
public string GetResponse(string prompt)
{
var chatCompletionsOptions = new ChatCompletionsOptions()
{
DeploymentName = "gpt-35-turbo",
Messages =
{
new ChatRequestUserMessage(prompt),
},
MaxTokens = 100
};
Response<ChatCompletions> response = _client.GetChatCompletions(chatCompletionsOptions);
return response.Value.Choices[0].Message.Content;
}
}
// Azure 客户端工厂
public class AzureOpenAIClientFactory : IApiClientFactory
{
private string _endpoint;
private string _key;
public AzureOpenAIClientFactory(string endpoint, string key)
{
_endpoint = endpoint;
_key = key;
}
// 创建Azure API客户端
public IApiClient CreateClient()
{
return new AzureOpenAIClient(_endpoint, _key);
}
}
using System;
class Program
{
static void Main(string[] args)
{
// 获取API终端和密钥(URL请求地址和KEY)
string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
// 创建客户端
IApiClientFactory factory = new AzureOpenAIClientFactory(endpoint, key);
IApiClient client = factory.CreateClient();
// 获取并打印响应
string response = client.GetResponse("Does Azure OpenAI support customer managed keys?");
Console.WriteLine(response);
}
}
from powertranslator.
提供Azure的ChatGPT的对接方式参考,这两家本质上一样,Azure多了一些请求头,以及自定义API地址,但它们返回和请求结构都一样的,但好在微软搞了SDK,C#写起来结构简约些。
也可以不用自己开发那么多,统一使用OPENAI的API,但提供自定义URL的方式。然后用户可以通过使用
https://github.com/songquanpeng/one-api
等类似项目自行适配。提示词可以通过一个文件配置配置提示词,纯示范:
=== Author: N0I0C0K Name: "PowerTranslator" Version: 0.01 === 你是一个翻译器。我会输入任何一种语言,你会通过如下的结构告知我{英语}的翻译结果,并给出不超过15个字的使用示范。如果有多个对应的翻译结果,可以在list中依次添加。最终使用统一的JSON结构回复,不需要除JSON以外的内容。 { "翻译结果": [], "属性": [ { "词性": "", "词根": "", "含义": "" } ] }
// API客户端工厂接口 public interface IApiClientFactory { IApiClient CreateClient(); } // API客户端接口 public interface IApiClient { string GetResponse(string prompt); }using Azure; using Azure.AI.OpenAI; using System; // Azure 客户端实现 public class AzureOpenAIClient : IApiClient { private OpenAIClient _client; public AzureOpenAIClient(string endpoint, string key) { _client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key)); } // 实现获取响应的方法 public string GetResponse(string prompt) { var chatCompletionsOptions = new ChatCompletionsOptions() { DeploymentName = "gpt-35-turbo", Messages = { new ChatRequestUserMessage(prompt), }, MaxTokens = 100 }; Response<ChatCompletions> response = _client.GetChatCompletions(chatCompletionsOptions); return response.Value.Choices[0].Message.Content; } } // Azure 客户端工厂 public class AzureOpenAIClientFactory : IApiClientFactory { private string _endpoint; private string _key; public AzureOpenAIClientFactory(string endpoint, string key) { _endpoint = endpoint; _key = key; } // 创建Azure API客户端 public IApiClient CreateClient() { return new AzureOpenAIClient(_endpoint, _key); } }using System; class Program { static void Main(string[] args) { // 获取API终端和密钥(URL请求地址和KEY) string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY"); // 创建客户端 IApiClientFactory factory = new AzureOpenAIClientFactory(endpoint, key); IApiClient client = factory.CreateClient(); // 获取并打印响应 string response = client.GetResponse("Does Azure OpenAI support customer managed keys?"); Console.WriteLine(response); } }
这个方法是可行的,很多翻译平台都提供了接口,但是无一例外他们都需要输入凭证,比如代码里面的AZURE_OPENAI_ENDPOINT
,这会加大下载人员的初始化难度,在插件里,我是选择了逆向了一些平台的web端翻译api,以此来给插件提供免费的翻译服务访问。
比较犹豫要不要在插件里加入这种需要自己输入api key的接口🫥
from powertranslator.
提供Azure的ChatGPT的对接方式参考,这两家本质上一样,Azure多了一些请求头,以及自定义API地址,但它们返回和请求结构都一样的,但好在微软搞了SDK,C#写起来结构简约些。
也可以不用自己开发那么多,统一使用OPENAI的API,但提供自定义URL的方式。然后用户可以通过使用https://github.com/songquanpeng/one-api
等类似项目自行适配。
提示词可以通过一个文件配置配置提示词,纯示范:=== Author: N0I0C0K Name: "PowerTranslator" Version: 0.01 === 你是一个翻译器。我会输入任何一种语言,你会通过如下的结构告知我{英语}的翻译结果,并给出不超过15个字的使用示范。如果有多个对应的翻译结果,可以在list中依次添加。最终使用统一的JSON结构回复,不需要除JSON以外的内容。 { "翻译结果": [], "属性": [ { "词性": "", "词根": "", "含义": "" } ] }
参考文档:https://learn.microsoft.com/en-us/azure/ai-services/openai/chatgpt-quickstart?tabs=command-line%2Cpython&pivots=programming-language-csharp// API客户端工厂接口 public interface IApiClientFactory { IApiClient CreateClient(); } // API客户端接口 public interface IApiClient { string GetResponse(string prompt); }using Azure; using Azure.AI.OpenAI; using System; // Azure 客户端实现 public class AzureOpenAIClient : IApiClient { private OpenAIClient _client; public AzureOpenAIClient(string endpoint, string key) { _client = new OpenAIClient(new Uri(endpoint), new AzureKeyCredential(key)); } // 实现获取响应的方法 public string GetResponse(string prompt) { var chatCompletionsOptions = new ChatCompletionsOptions() { DeploymentName = "gpt-35-turbo", Messages = { new ChatRequestUserMessage(prompt), }, MaxTokens = 100 }; Response<ChatCompletions> response = _client.GetChatCompletions(chatCompletionsOptions); return response.Value.Choices[0].Message.Content; } } // Azure 客户端工厂 public class AzureOpenAIClientFactory : IApiClientFactory { private string _endpoint; private string _key; public AzureOpenAIClientFactory(string endpoint, string key) { _endpoint = endpoint; _key = key; } // 创建Azure API客户端 public IApiClient CreateClient() { return new AzureOpenAIClient(_endpoint, _key); } }using System; class Program { static void Main(string[] args) { // 获取API终端和密钥(URL请求地址和KEY) string endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); string key = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY"); // 创建客户端 IApiClientFactory factory = new AzureOpenAIClientFactory(endpoint, key); IApiClient client = factory.CreateClient(); // 获取并打印响应 string response = client.GetResponse("Does Azure OpenAI support customer managed keys?"); Console.WriteLine(response); } }这个方法是可行的,很多翻译平台都提供了接口,但是无一例外他们都需要输入凭证,比如代码里面的
AZURE_OPENAI_ENDPOINT
,这会加大下载人员的初始化难度,在插件里,我是选择了逆向了一些平台的web端翻译api,以此来给插件提供免费的翻译服务访问。比较犹豫要不要在插件里加入这种需要自己输入api key的接口🫥
我是这么想的
如果有人用这个的话,那必然要有API,接触到这个的想必大部分人员应该是有开发能力的。
from powertranslator.
确实,考虑在下一个更新中添加一个需要提供api key的接口试一下🐱👓
from powertranslator.
Related Issues (20)
- powerToys 升级到 v0.72.0 后加载不了插件了 HOT 3
- 卡在Initializing... HOT 3
- 有计划添加支持微软翻译吗? HOT 2
- PowerToys 0.75.0 初始化插件失败 HOT 3
- 設定裡沒有目標語言 HOT 7
- 有些翻译莫名其妙,让人摸不着头脑。 HOT 5
- 关于安装路径 HOT 2
- PowerToys v0.76.0 报错 HOT 7
- PowerToys v 0.76.1上,图标无法正常显示的问题 HOT 2
- PowerToys 更新到v0.76.1后翻译插件v0.9报错 HOT 2
- PowerToys:0.76.2.0 Translator:0.9.2.2 出现先前报错 HOT 2
- 拷贝进去无任何反应。 HOT 4
- 可以支持添加显示的语言吗? HOT 3
- 能否在单个英文单词查询的场景下展示音标? HOT 2
- 当代理状态切换时,插件会失效 HOT 3
- 简化中文简繁体目标语言代码 HOT 2
- 增加对大小驼峰命名与snake命名的翻译支持 HOT 3
- More languages HOT 7
- 能否添加一个打开词典网页的功能 HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from powertranslator.