We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When does llms-with-matlab support Google Gemini?
The text was updated successfully, but these errors were encountered:
Thanks for the suggestion! We'll consider this as we move forward with our updates.
Sorry, something went wrong.
Here is an example you can try. I am assuming that you have your API key stored in the "gemini_api_key.env" file.
GEMINI_API_KEY=your_key
Here is a very simple MATLAB code.
loadenv("gemini_api_key.env") prompt = "Tell me 5 jokes"; response = geminiGenerateContent(prompt); if response.StatusCode == "OK" response.Body.Data.candidates.content.parts.text else response.Body.Data.error end
the function to call
function response = geminiGenerateContent(prompt, nvp) arguments prompt (1,1) {mustBeTextScalar,mustBeNonempty} nvp.image (1,1) {mustBeTextScalar} = ""; end if strlength(nvp.image) == 0 model = "gemini-pro"; query = struct("contents",[]); query.contents = {struct("parts",[])}; query.contents{1}.parts{1} = {struct("text",prompt)}; else model = "gemini-pro-vision"; if contains(nvp.image,["http://","https://"]) imdata = imread(nvp.image); imwrite(imdata,"imdata.png") img = "imdata.png"; else img = nvp.image; end fid = fopen(img); im = fread(fid,'*uint8'); fclose(fid); b64 = matlab.net.base64encode(im); [~,~,ext] = fileparts(img); MIMEType = "image/" + erase(ext,"."); query = struct("contents",[]); query.contents = {struct("parts",[])}; query.contents{1}.parts = {struct("text",prompt),struct("inline_data",[])}; query.contents{1}.parts{2}.inline_data = struct("mime_type",MIMEType,"data",[]); query.contents{1}.parts{2}.inline_data.data = b64; if isfile("imdata.png") delete("imdata.png") end end % endpoint = "https://generativelanguage.googleapis.com/v1beta/"; endpoint = "https://generativelanguage.googleapis.com/v1beta/"; method = "generateContent"; import matlab.net.* import matlab.net.http.* apikey = getenv("GEMINI_API_KEY"); headers = HeaderField('Content-Type', 'application/json'); request = RequestMessage('post', headers, query); response = send(request, URI(endpoint + ... "models/" + model + ... ":" + method + ... "?key=" + apikey)); end
debymf
No branches or pull requests
When does llms-with-matlab support Google Gemini?
The text was updated successfully, but these errors were encountered: