matgpt

版本 1.2.1.1 (303.3 kb) 作者:
matlab app and class to access chatgpt api from openai

3.7k 次下载

更新时间 2023/4/19

来自 github

matgpt -凯发k8网页登录

matgpt is a matlab app powered by chatgpt class that allows you to easily access the chatgpt api provided by openai. with the app, you can load a list of prompts for specific use cases and engage in conversations with ease. if you're new to chatgpt and prompt engineering, matgpt is a great way to learn. if you're already familiar with chatgpt, you can directly use the class.

the app and class simply serve as an interface to the chatgpt api. you should be familiar with the limitations and risks associated with using this technology as well as with . you are responsible for any fees openai may charge for the use of their api.

requirements

  • mathworks products (): to use matgpt, you need to have matlab r2021a or later installed on your computer.
  • openai api key: additionally, you will need your own api key from .

installation

  1. download the content of this repository into a matlab path.
  2. launch matlab
  3. before using, set an environment variable with your openai api key named openai_api_key. you can also set an environmental variable using the settings in the app.
setenv("openai_api_key","your key here")
  1. open matgpt.mlapp in app designer and click 'run'

how to use: matgpt app

  1. click on " new chat" in the left nav to add a new chat. this opens the settings tab.
  2. in the settings tab, either choose a preset to populate the settings or customize on your own. once you have completed the settings, click "start new chat" to initiate a chat. this will take you back to the main tab.
  • presets are loaded from - feel free to customize your prompts.
  1. in the main tab, a sample prompt is already provided based on the preset you selected, but feel free to replace it with your own. when you click send button, the response will be shown in the 'chat' tab.
  • the send button is disabled until a chat is configured in the settings tab.
  • if your prompt is intended to generate matlab code, check test generated matlab code checkbox to test the returned code.
  • the usage tab shows number of tokens used and the cost incurred in the current chat session.
  1. continue the conversation by keep adding more prompts and clicking send.
  2. you can right-click a chat in the left nav to rename, delete, or save the chat to a text file.
  3. when you close the app, the chat will be saved and will be reloaded into the left nav when you relaunch the app.

how to use: chatgpt class

chatgpt class creates an instance to access openai api using your own api key, and optionally max_tokens that determine the length of the response. once you create an instance, then you can use its chat method to post prompt via openapi chatgpt api released on march 1, 2023.

where to find it

class is located in helpers folder.

set up the bot

first, make sure you set your openai api key in the environment variable as shown above. create an instance using the default parameters. your api key will be loaded from the os environment variable.

mybot = chatgpt();

you can also set max_tokens parameter, which determines the length of the response. if you don't specify max_tokens, the response will be limited to up to 1000 tokens. the max_tokens must be less than 4096.

mybot = chatgpt(max_tokens=50);

you can also specify other parameters, such as model and temperature.

  • models: gpt-3.5-turbo (default - stable release), gpt-3.5-turbo-0301 (latest release)
  • temperature: 0 = more strict, 1 = balanced, 2 = more creative

you can pass a role to prime the chatbot for a specific use case. by default the chatbot is primed to act as an ai assistant, using the prompt "you are a helpful assistant." you can customize this for specific use cases.

role = "you define the role the chatbot should play.";
mybot = chatgpt(model="gpt-3.5-turbo", max_tokens=1000, temperature=0.9,role=role);

chat with the bot

use the instance you created to send your prompt to the api.

answer = chat(mybot,"your prompt")

you will get an error if the api didn't return response successfully.

check the token usage

use usage method to obtain the total number of tokens used in the current session. it returns both the number of tokens as well as the cost.

[tokens,cost] = usage(mybot)

save the chat history

use savechat method to save the chat history to a file. the supported format includes .mat, .xlsx, and .json.

[tokens,cost] = savechat(mybot,format=".xlsx")

chatgpt class example

role = "you are a matlab expert who only answers with code with no explanation.";
mybot = chatgpt(model="gpt-3.5-turbo", max_tokens=1000, temperature=0.9, role=role);
answer = chat(mybot, "generate 10x10 matrix using integers from 0 to 9.")

acknowledgements

this code is adapted from by and uses 's and other great contributions.

license

the license for matgpt is available in the file in this github repository.

引用格式

toshiaki takeuchi (2023). matgpt (https://github.com/toshiakit/matgpt/releases/tag/1.2.1.1), github. 检索来源 .

matlab 版本兼容性
创建方式 r2022b
与 r2020a 及更高版本兼容
平台兼容性
windows macos linux
标签

community treasure hunt

find the treasures in matlab central and discover how the community can help you!

start hunting!

helpers

版本 已发布 发行说明
1.2.1.1

see release notes for this release on github:

1.2.1.0

see release notes for this release on github:

1.2.0.0

see release notes for this release on github:

1.1.0.0

see release notes for this release on github:

1.0.0
要查看或报告此来自 github 的附加功能中的问题,请访问其 。
要查看或报告此来自 github 的附加功能中的问题,请访问其 。
网站地图