隨著國(guó)外AI大模型訓(xùn)練平臺(tái),并附上代碼示例,幫助初級(jí)用戶快速上手。
生成式AI領(lǐng)域的先驅(qū),其開(kāi)發(fā)的 GPT-4 和 GPT-3.5 Turbo 模型在自然語(yǔ)言處理(NLP)任務(wù)中表現(xiàn)卓越。用戶可以通過(guò) OpenAI API 調(diào)用模型進(jìn)行文本生成、代碼編寫、多輪對(duì)話等操作。
import openai openai.api_key = "your-api-key" response = openai.ChatCompletion.create( model="gpt-3.5-turbo", messages=[ {"role": "user", "content": "用100字解釋什么是人工智能?"} ] ) print(response.choices[0].message.content)
Google 的 Gemini 是首個(gè)支持文本、圖像、音頻多模態(tài)輸入的大模型,尤其擅長(zhǎng)跨模態(tài)推理和復(fù)雜任務(wù)處理。開(kāi)發(fā)者可通過(guò) Gemini API 構(gòu)建智能應(yīng)用。
import google.generativeai as genai genai.configure(api_key="your-api-key") model = genai.GenerativeModel('gemini-pro-vision')# 上傳圖片并提問(wèn) response = model.generate_content([ "這張圖片中有幾只貓?", genai.upload_file("cat_image.jpg") ]) print(response.text)
API 支持長(zhǎng)文本處理和復(fù)雜推理。
from anthropic import Anthropic client = Anthropic(api_key="your-api-key") response = client.messages.create( model="claude-3-opus-20240229", max_tokens=200, messages=[ {"role": "user", "content": "請(qǐng)用三句話總結(jié)以下文章:[長(zhǎng)文本內(nèi)容]"} ] ) print(response.content[0].text)
Mistral AI 專注于開(kāi)源模型研發(fā),其 Mistral-7B 和 Codestral 模型以高性能和低訓(xùn)練成本著稱,適合開(kāi)發(fā)者自行訓(xùn)練和定制。
from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-v0.1") model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-v0.1")inputs = tokenizer("如何用Python實(shí)現(xiàn)快速排序?", return_tensors="pt") outputs = model.generate(**inputs, max_length=200) print(tokenizer.decode(outputs[0], skip_special_tokens=True))
微軟的 Copilot 深度集成于Office 365、GitHub等產(chǎn)品中,提供代碼生成、文檔撰寫、數(shù)據(jù)分析等場(chǎng)景的智能輔助。
(通過(guò)IDE插件直接交互,無(wú)需獨(dú)立API調(diào)用)