Giter VIP home page Giter VIP logo

Comments (9)

N0I0C0K avatar N0I0C0K commented on May 28, 2024

当然可以!我正打算加入多个接口选择,目前的加入顺序是:

  1. Google
  2. Bing

当然如果你想帮助我完成其他接口的接入,我预留了接口在 src/Youdao/ITranslater.cs ,可以很方便接入一个新的翻译引擎!

from powertranslator.

pilgrimlyieu avatar pilgrimlyieu commented on May 28, 2024

当然可以!我正打算加入多个接口选择,目前的加入顺序是:

  1. Google 谷歌
  2. Bing 必应

当然如果你想帮助我完成其他接口的接入,我预留了接口在 src/Youdao/ITranslater.cs ,可以很方便接入一个新的翻译引擎!

感谢!可惜我心有余而力不足,并不了解相关内容,恐怕很难向您提供有益的帮助。

另外我在使用过程中发现一个点,使用 Ctrl + Enter 进行朗读时直接关闭了 PT,但是朗读这个功能并不适合立刻关闭 PT 吧?当然只是我个人的看法,如果有方法可供调整我认为就更好了。

from powertranslator.

N0I0C0K avatar N0I0C0K commented on May 28, 2024

对,之前我也发现了这个问题,按道理确实不应该关,我在代码里的实现也是朗读不关PT,但是好像不论我是否设置他关闭,只要有enter按下,始终都会关闭,我会在后面持续关注这个问题!

from powertranslator.

pilgrimlyieu avatar pilgrimlyieu commented on May 28, 2024

对,之前我也发现了这个问题,按道理确实不应该关,我在代码里的实现也是朗读不关PT,但是好像不论我是否设置他关闭,只要有enter按下,始终都会关闭,我会在后面持续关注这个问题!

好的,再次感谢,期待插件的后续更新!

from powertranslator.

yinleiCoder avatar yinleiCoder commented on May 28, 2024

期待添加google翻译

from powertranslator.

LeXwDeX avatar LeXwDeX commented on May 28, 2024

提供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以外的内容。

{
    "翻译结果": [],
    "属性": [
        {
            "词性": "",
            "词根": "",
            "含义": ""
        }
    ]
}

image


参考文档: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);
    }
}

from powertranslator.

N0I0C0K avatar N0I0C0K commented on May 28, 2024

提供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以外的内容。

{
    "翻译结果": [],
    "属性": [
        {
            "词性": "",
            "词根": "",
            "含义": ""
        }
    ]
}

image

参考文档: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的接口🫥

from powertranslator.

LeXwDeX avatar LeXwDeX commented on May 28, 2024

提供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以外的内容。

{
    "翻译结果": [],
    "属性": [
        {
            "词性": "",
            "词根": "",
            "含义": ""
        }
    ]
}

image
参考文档: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.

N0I0C0K avatar N0I0C0K commented on May 28, 2024

确实,考虑在下一个更新中添加一个需要提供api key的接口试一下🐱‍👓

from powertranslator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.