|
21 | 21 | "cell_type": "code", |
22 | 22 | "execution_count": null, |
23 | 23 | "metadata": {}, |
24 | | - "outputs": [], |
| 24 | + "outputs": [ |
| 25 | + { |
| 26 | + "name": "stderr", |
| 27 | + "output_type": "stream", |
| 28 | + "text": [ |
| 29 | + "/opt/homebrew/Caskroom/miniforge/base/envs/random/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", |
| 30 | + " from .autonotebook import tqdm as notebook_tqdm\n" |
| 31 | + ] |
| 32 | + } |
| 33 | + ], |
25 | 34 | "source": [ |
26 | 35 | "#| export\n", |
27 | 36 | "\n", |
|
108 | 117 | "### Example usage" |
109 | 118 | ] |
110 | 119 | }, |
| 120 | + { |
| 121 | + "cell_type": "code", |
| 122 | + "execution_count": null, |
| 123 | + "metadata": {}, |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "data": { |
| 127 | + "text/plain": [ |
| 128 | + "True" |
| 129 | + ] |
| 130 | + }, |
| 131 | + "execution_count": null, |
| 132 | + "metadata": {}, |
| 133 | + "output_type": "execute_result" |
| 134 | + } |
| 135 | + ], |
| 136 | + "source": [ |
| 137 | + "from dotenv import load_dotenv\n", |
| 138 | + "\n", |
| 139 | + "# Load environment variables from a .envrc file\n", |
| 140 | + "load_dotenv('/Users/shahules/Myprojects/ragas_annotator/.envrc')" |
| 141 | + ] |
| 142 | + }, |
111 | 143 | { |
112 | 144 | "cell_type": "code", |
113 | 145 | "execution_count": null, |
|
117 | 149 | "name": "stdout", |
118 | 150 | "output_type": "stream", |
119 | 151 | "text": [ |
120 | | - "[0, 1, 2]\n", |
| 152 | + "[2, 1, 0]\n", |
121 | 153 | "Ensemble ranking based on multiple evaluations.\n", |
122 | | - "The ranking is based on the length and detail of the responses, with 'short answer.' being the least detailed (rank 0), 'a bit more detailed.' being moderate (rank 1), and 'the longest and most detailed answer.' being the most comprehensive (rank 2).\n", |
123 | | - "The ranking is based on the length and detail of the responses. The shortest response is ranked the lowest (0), the moderately detailed response is ranked higher (1), and the longest and most detailed response is ranked the highest (2).\n", |
124 | | - "Ranking is based on length and detail; the longest answer (2) is most detailed, followed by a bit more detailed (1), and the shortest answer (0) is the least detailed.\n" |
| 154 | + "The ranking is based on the length and detail of each response. 'the longest and most detailed answer.' is the most comprehensive, followed by 'a bit more detailed.', and 'short answer.' is the briefest.\n", |
| 155 | + "The ranking is based on the length and detail of each response. The response 'the longest and most detailed answer.' is ranked highest (2) because it is the most detailed, followed by 'a bit more detailed.' (1), and finally 'short answer.' (0) as it is the least detailed.\n", |
| 156 | + "The responses are ranked based on the level of detail and length. 'short answer.' is the least detailed, 'a bit more detailed.' provides more information, and 'the longest and most detailed answer.' offers the most comprehensive explanation.\n" |
125 | 157 | ] |
126 | 158 | } |
127 | 159 | ], |
128 | 160 | "source": [ |
129 | 161 | "\n", |
130 | 162 | "#| eval: false\n", |
131 | 163 | "\n", |
132 | | - "from ragas_annotator.metric.llm import LLM\n", |
| 164 | + "from ragas_annotator.llm import ragas_llm\n", |
| 165 | + "from openai import OpenAI\n", |
| 166 | + "\n", |
| 167 | + "llm = ragas_llm(provider=\"openai\",model=\"gpt-4o\",client=OpenAI())\n", |
133 | 168 | "\n", |
134 | 169 | "my_ranking_metric = RankingMetric(\n", |
135 | 170 | " name='response_ranking',\n", |
136 | | - " llm=LLM(), # Your language model instance\n", |
| 171 | + " llm=llm, # Your language model instance\n", |
137 | 172 | " prompt=\"Rank the following responses:\\n{candidates}\",\n", |
138 | 173 | " num_ranks=3,\n", |
139 | 174 | ")\n", |
|
175 | 210 | "\n", |
176 | 211 | "\n", |
177 | 212 | "@ranking_metric(\n", |
178 | | - " llm=LLM(), # Your language model instance\n", |
| 213 | + " llm=llm, # Your language model instance\n", |
179 | 214 | " prompt=\"Rank the following responses:\\n{candidates}\",\n", |
180 | 215 | " name='new_ranking_metric',\n", |
181 | 216 | " num_ranks=3\n", |
|
0 commit comments