Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

Commit 22655d1

Browse files
committed
doc: add script
1 parent 3e0a15f commit 22655d1

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

scripts/langchain.ipynb

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

scripts/sample.ipynb

+11-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"import string\n",
1515
"\n",
1616
"# Assuming 'cookies' is defined somewhere\n",
17+
"cookies = {}\n",
1718
"\n",
1819
"url = \"https://gemini.google.com/app\"\n",
1920
"response = requests.get(url, cookies=cookies)\n",
@@ -23,8 +24,8 @@
2324
"reqid = int(\"\".join(random.choices(string.digits, k=7)))\n",
2425
"\n",
2526
"url_params = {\n",
26-
" \"bl\": \"boq_assistant-bard-web-server_20240227.13_p0\",\n",
27-
" \"hl\": \"en\",\n",
27+
" \"bl\": \"boq_assistant-bard-web-server_20240227.13_p0\", # This will be changed as it updated.\n",
28+
" \"hl\": \"en\", # You can replace language. Refer README.md.\n",
2829
" \"_reqid\": reqid,\n",
2930
" \"rt\": \"c\",\n",
3031
" \"f.sid\": sid,\n",
@@ -34,7 +35,7 @@
3435
"\n",
3536
"data = {\n",
3637
" \"at\": nonce,\n",
37-
" \"f.req\": json.dumps([None, json.dumps([[\"How can I use you. what can you do?\"], None, None and None])]),\n",
38+
" \"f.req\": json.dumps([None, json.dumps([[\"How can I use you. what can you do?\"], None, None and None])]), # Prompt and data structure.\n",
3839
"}\n",
3940
"\n",
4041
"data_encoded = urllib.parse.urlencode(data)\n",
@@ -67,8 +68,14 @@
6768
}
6869
],
6970
"metadata": {
71+
"kernelspec": {
72+
"display_name": "edanif",
73+
"language": "python",
74+
"name": "edanif"
75+
},
7076
"language_info": {
71-
"name": "python"
77+
"name": "python",
78+
"version": "3.9.12"
7279
}
7380
},
7481
"nbformat": 4,

0 commit comments

Comments
 (0)