|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [], |
| 8 | + "source": [ |
| 9 | + "# https://github.com/drmwnrafi \n", |
| 10 | + "from gemini import Gemini\n", |
| 11 | + "from typing import Any, List, Mapping, Optional\n", |
| 12 | + "from langchain.callbacks.manager import CallbackManagerForLLMRun\n", |
| 13 | + "from langchain.llms.base import LLM\n", |
| 14 | + "\n", |
| 15 | + "cookies = {}\n", |
| 16 | + "\n", |
| 17 | + "class GeminiLLM(LLM):\n", |
| 18 | + " @property\n", |
| 19 | + " def _llm_type(self) -> str:\n", |
| 20 | + " return \"custom\"\n", |
| 21 | + "\n", |
| 22 | + " def _call(self, prompt: str, stop: Optional[List[str]] = None,run_manager: Optional[CallbackManagerForLLMRun] = None) -> str:\n", |
| 23 | + " response = Gemini(cookies=cookies).generate_content(prompt)['text']\n", |
| 24 | + " return response\n", |
| 25 | + "\n", |
| 26 | + " @property\n", |
| 27 | + " def _identifying_params(self) -> Mapping[str, Any]:\n", |
| 28 | + " \"\"\"Get the identifying parameters.\"\"\"\n", |
| 29 | + " return {}\n", |
| 30 | + "\n", |
| 31 | + "llm = GeminiLLM()\n", |
| 32 | + "\n", |
| 33 | + "llm(\"Who are you?\")\n", |
| 34 | + "\n", |
| 35 | + "\"\"\" \n", |
| 36 | + "Output : I am Bard, a large language model from Google AI. I am trained on a massive dataset of text and code, and I can generate text, translate languages, write different kinds of creative content, and answer your questions in an informative way. I am still under development, but I have learned to perform many kinds of tasks, including\n", |
| 37 | + "\n", |
| 38 | + "* I will try my best to follow your instructions and complete your requests thoughtfully.\n", |
| 39 | + "* I will use my knowledge to answer your questions in a comprehensive and informative way, even if they are open ended, challenging, or strange.\n", |
| 40 | + "* I will generate different creative text formats of text content, like poems, code, scripts, musical pieces, email, letters, etc. I will try my best to fulfill all your requirements.\n", |
| 41 | + "\n", |
| 42 | + "I am excited to be able to help people with their tasks and creative projects, and I hope to learn and grow more over time.\n", |
| 43 | + "\n", |
| 44 | + "What can I help you with today? \n", |
| 45 | + "\"\"\" " |
| 46 | + ] |
| 47 | + } |
| 48 | + ], |
| 49 | + "metadata": { |
| 50 | + "language_info": { |
| 51 | + "name": "python" |
| 52 | + } |
| 53 | + }, |
| 54 | + "nbformat": 4, |
| 55 | + "nbformat_minor": 2 |
| 56 | +} |
0 commit comments