acalejos commited on
Commit
0ae9041
1 Parent(s): e8e898d

Rename public-apps/welcome.livemd to public-apps/github-repo-report.livemd

Browse files
public-apps/github-repo-report.livemd ADDED
@@ -0,0 +1,710 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- livebook:{"app_settings":{"access_type":"public","output_type":"rich","slug":"report"}} -->
2
+
3
+ # GitHub Repo Report and Analysis
4
+
5
+ ```elixir
6
+ Mix.install(
7
+ [
8
+ {:req, "~> 0.4.0"},
9
+ {:json, "~> 1.4"},
10
+ {:instructor, github: "acalejos/instructor_ex"},
11
+ {:exterval, "~> 0.2.0"},
12
+ {:kino, "~> 0.12.3"}
13
+ ],
14
+ config: [
15
+ instructor: [
16
+ adapter: Instructor.Adapters.OpenAI
17
+ ],
18
+ openai: [http_options: [recv_timeout: 10 * 60 * 1000]]
19
+ ]
20
+ )
21
+ ```
22
+
23
+ ## Github Searching
24
+
25
+ ```elixir
26
+ defmodule Report do
27
+ use Ecto.Schema
28
+ use Instructor.Validator
29
+ import Ecto.Changeset
30
+
31
+ import Exterval
32
+ @score_interval ~i<[0,10]//0.5>
33
+
34
+ @categories [
35
+ :software_library,
36
+ :list_aggregation,
37
+ :educational_tutorial,
38
+ :documentation_reference,
39
+ :configuration_dotfiles,
40
+ :template_boilerplate,
41
+ :data_dataset,
42
+ :tool_utility,
43
+ :art_design,
44
+ :hardware_iot,
45
+ :research_academic,
46
+ :demo_example,
47
+ :community_social,
48
+ :game_development
49
+ ]
50
+
51
+ @doc """
52
+ ## Field Descriptions:
53
+ - repository_details: A summary of the repository details, including facts such as name, owner, descriptions, number of stargazers, licenseInfo, createdAt, pushedAt, isArchived, primaryLanguage, topics, etc. Your answer should be between 750 to 1000 characters
54
+ - category: Categorizes the nature and purpose of the GitHub repository. It aids in quickly identifying the type of content or project a repository contains. This field provides vital information for someone determining the relevance and scope of a project. The field accepts predefined atom values representing various types of repositories typically found on GitHub. These categories include:
55
+ - `:software_library` - Traditional coding projects like applications, frameworks, or libraries.
56
+ - `:list_aggregation` - Collections of resources such as awesome lists or curated topic lists.
57
+ - `:educational_tutorial` - Repositories focusing on educational content, tutorials, or learning exercises.
58
+ - `:documentation_reference` - Projects mainly containing documentation, reference material, or specifications.
59
+ - `:configuration_dotfiles` - Repositories for configuration files or dotfiles for software/tool setups.
60
+ - `:template_boilerplate` - Starter templates or boilerplates for kickstarting development.
61
+ - `:data_dataset` - Repos hosting or linking to datasets for research or analysis.
62
+ - `:tool_utility` - Repos containing specific tools, scripts, or utilities.
63
+ - `:art_design` - Projects related to art, graphics, or design resources.
64
+ - `:hardware_iot` - Repositories about hardware, IoT, or physical computing projects.
65
+ - `:research_academic` - Academic or scholarly research, papers, or experiments.
66
+ - `:demo_example` - Example or demo projects illustrating concepts or technologies.
67
+ - `:community_social` - Repos focused on community building or social initiatives.
68
+ - `:game_development` - Game development-related projects, engines, or games.
69
+ - language: The detected natural language (eg. English, Spanish, etc.) of the repository according to any natural language inputs found from fields such as the README, Git Commit Messages, Issue Messages, Repo Description, etc. The description and README should be weighted higher than all other sources.
70
+ - activity_metrics: A summary of the repository's activity based on factors such as commitComments, issues (history, activity, comments, etc.), pull requests, etc. Your answer should be between 750 to 1000 characters.
71
+ - community_involvement: A summary of the community involvement based on factors such as forkCount, watchers, contributors, discussions, mergeRequest discussions, etc. Your answer should be between 750 to 1000 characters.
72
+ - development_practices: A summary of the development practices seen throughout the repo based on factors such as branch_protection_rules, latest_release_info, and other version-control meta controls. Your answer should be between 750 to 1000 characters.
73
+ - skill_score: Rating from 0 to 10 in increments of 0.5 of how much expertise a new maintainer should have to consider taking on the development related to this repo. 0 is very easy (think Awesome lists which just aggregate other repos, lists, etc.), while 10 is extrmely difficult (think something like an OS kernel).
74
+ - potential_score: Rating from 0 to 10 in increments of 0.5 of how suitable the repo is for continued development if it were to be re-opened by a current user. Scored the repo on the future potential development.
75
+ - conclusion: Summarize your analysis of this repository with respect to its technical applicability, potential for future work, and skill required to work with it. Your conclusion should incorporate aspect of every other field, and should serve as a comprehensive summarization of the repository, its community, and its practices. Your answer should be between 1250 to 1500 characters
76
+ """
77
+ @primary_key false
78
+ embedded_schema do
79
+ field(:repository_details, :string)
80
+ field(:category, Ecto.Enum, values: @categories)
81
+ field(:language, :string)
82
+ field(:activity_metrics, :string)
83
+ field(:community_involvement, :string)
84
+ field(:development_practices, :string)
85
+ field(:skill_score, :float)
86
+ field(:potential_score, :float)
87
+ field(:conclusion, :string)
88
+ end
89
+
90
+ @impl true
91
+ def validate_changeset(changeset) do
92
+ changeset
93
+ |> validate_inclusion(:skill_score, @score_interval)
94
+ |> validate_inclusion(:potential_score, @score_interval)
95
+ end
96
+ end
97
+ ```
98
+
99
+ ```elixir
100
+ defmodule ReportGenerator do
101
+ @req Req.new(base_url: "https://api.github.com/graphql")
102
+
103
+ def cleanup_nodes(nodes) do
104
+ max_readme_length = 300
105
+ issueCharLimit = 300
106
+
107
+ nodes
108
+ |> Enum.map(fn node ->
109
+ {topics, related_topics} =
110
+ node
111
+ |> get_in(["repositoryTopics", "nodes"])
112
+ |> Enum.reduce(
113
+ {[], []},
114
+ fn %{"topic" => %{"name" => topic_name, "relatedTopics" => topic_related}},
115
+ {topics_acc, related_acc} ->
116
+ topic_related =
117
+ Enum.reduce(topic_related, [], fn curr, acc ->
118
+ if Map.has_key?(curr, "name"), do: [Map.fetch!(curr, "name") | acc], else: acc
119
+ end)
120
+
121
+ {[topic_name | topics_acc], related_acc ++ topic_related}
122
+ end
123
+ )
124
+
125
+ %{"totalCount" => openIssueCount, "nodes" => openIssues} = Map.get(node, "openIssues")
126
+ %{"totalCount" => closedIssueCount, "nodes" => closedIssues} = Map.get(node, "closedIssues")
127
+
128
+ [closedIssues, openIssues] =
129
+ Enum.zip_reduce([openIssues, closedIssues], [[], []], fn [
130
+ %{"bodyText" => openText} =
131
+ openIssue,
132
+ %{"bodyText" => closedText} =
133
+ closedIssue
134
+ ],
135
+ [openAcc, closedAcc] ->
136
+ openIssue =
137
+ Map.replace!(openIssue, "bodyText", openText |> String.slice(0..(issueCharLimit - 1)))
138
+
139
+ closedIssue =
140
+ Map.replace!(
141
+ closedIssue,
142
+ "bodyText",
143
+ closedText |> String.slice(0..(issueCharLimit - 1))
144
+ )
145
+
146
+ [[openIssue | openAcc], [closedIssue | closedAcc]]
147
+ end)
148
+
149
+ readme =
150
+ (Map.get(node, "readmeMD") || Map.get(node, "readme") || Map.get(node, "readmeLowerMD"))
151
+ |> Map.update("text", "", fn text ->
152
+ text
153
+ |> String.split(" ", trim: true)
154
+ |> Enum.slice(0..max_readme_length)
155
+ |> Enum.join(" ")
156
+ end)
157
+
158
+ node
159
+ |> Map.replace!("repositoryTopics", topics)
160
+ |> Map.put_new("relatedTopics", related_topics)
161
+ |> Map.replace!("readme", readme)
162
+ |> Map.reject(fn {k, _v} -> k in ["readmeMD", "readmeLowerMD"] end)
163
+ |> Map.replace!("openIssues", openIssues)
164
+ |> Map.replace!("closedIssues", closedIssues)
165
+ |> Map.put_new("openIssueCount", openIssueCount)
166
+ |> Map.put_new("closedIssueCount", closedIssueCount)
167
+ end)
168
+ end
169
+
170
+ def run_query(repoOwner, repoName, gh_tok) do
171
+ query = """
172
+ query getRepoReport($repoName: String!, $repoOwner: String!) {
173
+ repository(name: $repoName, owner: $repoOwner) {
174
+ commitComments(after: null, first: 5) {
175
+ nodes {
176
+ bodyText
177
+ }
178
+ }
179
+ squashMergeAllowed
180
+ squashMergeCommitTitle
181
+ squashMergeCommitMessage
182
+ webCommitSignoffRequired
183
+ openPRs: pullRequests(first: 5, after: null, states: OPEN) {
184
+ totalCount
185
+ nodes {
186
+ totalCommentsCount
187
+ merged
188
+ participants(first: 100, after: null) {
189
+ totalCount
190
+ }
191
+ }
192
+ }
193
+ closedPRs: pullRequests(first: 5, after: null, states: CLOSED) {
194
+ totalCount
195
+ nodes {
196
+ totalCommentsCount
197
+ merged
198
+ participants(first: 100, after: null) {
199
+ totalCount
200
+ }
201
+ }
202
+ }
203
+ deleteBranchOnMerge
204
+ deployments(first: 5, after: null) {
205
+ nodes {
206
+ task
207
+ payload
208
+ }
209
+ }
210
+ discussions(first: 5, after: null) {
211
+ nodes {
212
+ answer {
213
+ minimizedReason
214
+ }
215
+ labels {
216
+ nodes {
217
+ name
218
+ }
219
+ }
220
+ }
221
+ }
222
+ latestRelease {
223
+ name
224
+ tagName
225
+ createdAt
226
+ updatedAt
227
+ }
228
+ mergeCommitAllowed
229
+ openIssues: issues(states: OPEN, first: 10, after: null) {
230
+ totalCount
231
+ nodes {
232
+ title
233
+ bodyText
234
+ }
235
+ }
236
+ closedIssues: issues(states: CLOSED, first: 5, after: null) {
237
+ totalCount
238
+ nodes {
239
+ title
240
+ bodyText
241
+ }
242
+ }
243
+ isLocked
244
+ forkCount
245
+ forkingAllowed
246
+ hasDiscussionsEnabled
247
+ hasIssuesEnabled
248
+ hasVulnerabilityAlertsEnabled
249
+ hasWikiEnabled
250
+ isFork
251
+ isSecurityPolicyEnabled
252
+ readmeMD: object(expression: "HEAD:README.md") {
253
+ ... on Blob {
254
+ text
255
+ }
256
+ }
257
+ readme: object(expression: "HEAD:README") {
258
+ ... on Blob {
259
+ text
260
+ }
261
+ }
262
+ readmeLowerMD: object(expression: "HEAD:readme.md") {
263
+ ... on Blob {
264
+ text
265
+ }
266
+ }
267
+ name
268
+ primaryLanguage {
269
+ name
270
+ }
271
+ contactLinks {
272
+ name
273
+ about
274
+ url
275
+ }
276
+ createdAt
277
+ description
278
+ updatedAt
279
+ stargazerCount
280
+ homepageUrl
281
+ url
282
+ owner {
283
+ avatarUrl
284
+ login
285
+ url
286
+ }
287
+ openGraphImageUrl
288
+ pushedAt
289
+ repositoryTopics(after: null, first: 5) {
290
+ totalCount
291
+ nodes {
292
+ topic {
293
+ name
294
+ relatedTopics {
295
+ name
296
+ }
297
+ }
298
+ }
299
+ }
300
+ }
301
+ }
302
+ """
303
+
304
+ variables = %{"repoName" => repoName, "repoOwner" => repoOwner}
305
+
306
+ Req.post(
307
+ @req,
308
+ headers: %{"Authorization" => "bearer #{gh_tok}"},
309
+ json: %{"query" => query, "variables" => variables}
310
+ )
311
+ end
312
+
313
+ def get_report(gql_response, oai_token, model) do
314
+ Instructor.chat_completion(
315
+ model: model,
316
+ response_model: Report,
317
+ max_retries: 3,
318
+ messages: [
319
+ %{
320
+ role: "user",
321
+ content: """
322
+ I'm making a website that showcases Github repos that have been abandoned, but have
323
+ a lot of stars and permissive licenses. This is to allow people to look for potential
324
+ projects that they can fork, take over, or use freely. I want to have premium Reports
325
+ that people can look at that summarize some of the history of the project. Im using
326
+ the GitHub Graphql API. What fields and/or items should I use from the API to help
327
+ synthesize these reports? My idea is to generate these reports using an LLM that
328
+ is given these items from the API and generates the reports according to a predefined
329
+ structure.
330
+
331
+ Your job is to write these reports in a professional, but not stiff manner.
332
+ Assume that people are paying a premium for these reports, so they must provide good
333
+ insight based on the given information from the GitHub GraphQL API. These results
334
+ should be presentable as a dossier about the repository in question,
335
+ and should make conclusions derived from the available data. The conclusions should
336
+ be well thought out, and not simply restating the facts.
337
+
338
+
339
+ Here is the result of the GrapqhQL Response from Github: #{Jason.encode!(gql_response)}
340
+ """
341
+ }
342
+ ],
343
+ config: %OpenAI.Config{
344
+ http_options: [recv_timeout: 10 * 60 * 1000],
345
+ api_key: oai_token
346
+ }
347
+ )
348
+ end
349
+
350
+ def generate_report(path, gh_tok, oai_tok, model) do
351
+ case String.split(path, "/") do
352
+ [owner, repo] ->
353
+ case run_query(owner, repo, gh_tok) do
354
+ {:ok, %Req.Response{status: 200, body: body}} ->
355
+ get_report(body["data"], oai_tok, model)
356
+
357
+ {:ok, %Req.Response{body: body}} ->
358
+ {:error,
359
+ "Something went wrong when communicating with the GitHub API. #{body["message"]}."}
360
+
361
+ {:error, _exception} ->
362
+ {:error,
363
+ "Something went wrong when communicating with the GitHub API. Try again later."}
364
+ end
365
+
366
+ _ ->
367
+ {:error, "Repo must be in the form own 'owner/repo', got #{inspect(path)}"}
368
+ end
369
+ end
370
+ end
371
+ ```
372
+
373
+ ```elixir
374
+ defmodule LiveReport do
375
+ use Kino.JS
376
+ use Kino.JS.Live
377
+
378
+ @empty_state """
379
+ <!DOCTYPE html>
380
+ <html lang="en">
381
+ <head>
382
+ <meta charset="UTF-8">
383
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
384
+ <title>Report</title>
385
+ <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
386
+ </head>
387
+ <body>
388
+ <button class="relative block w-full rounded-lg border-2 border-dashed border-gray-300 p-12 text-center hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2">
389
+ <svg class="mx-auto h-12 w-12 text-gray-400" stroke="currentColor" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6">
390
+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m0 12.75h7.5m-7.5 3H12M10.5 2.25H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z" />
391
+ </svg>
392
+ <span class="mt-2 block text-sm font-semibold text-gray-900">Generate Your Report to See it Here!</span>
393
+ </button>
394
+ </body>
395
+ </html>
396
+ """
397
+
398
+ def new() do
399
+ Kino.JS.Live.new(__MODULE__, nil)
400
+ end
401
+
402
+ def replace(kino, report, origin) do
403
+ Kino.JS.Live.call(kino, {:replace, report, origin})
404
+ end
405
+
406
+ def loading(kino, origin) do
407
+ Kino.JS.Live.call(kino, {:replace, :loading, origin})
408
+ end
409
+
410
+ def download_html(kino) do
411
+ Kino.JS.Live.call(kino, {:download})
412
+ end
413
+
414
+ defp format_category(category) do
415
+ category
416
+ |> Atom.to_string()
417
+ |> String.split("_")
418
+ |> Enum.map(&String.capitalize/1)
419
+ |> Enum.join(" ")
420
+ end
421
+
422
+ @impl true
423
+ def init(_report, ctx) do
424
+ {:ok, assign(ctx, html: @empty_state)}
425
+ end
426
+
427
+ @impl true
428
+ def handle_connect(ctx) do
429
+ {:ok, @empty_state, ctx}
430
+ end
431
+
432
+ @impl true
433
+ def handle_call({:download}, _from, ctx) do
434
+ {:reply, ctx.html, nil}
435
+ end
436
+
437
+ def handle_call({:replace, %Report{} = report, origin}, _from, ctx) do
438
+ report_html =
439
+ """
440
+ <!DOCTYPE html>
441
+ <html lang="en">
442
+ <head>
443
+ <meta charset="UTF-8">
444
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
445
+ <title>Report</title>
446
+ <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
447
+ </head>
448
+ <body class="bg-gray-100">
449
+ <div class="container mx-auto p-6 mt-10 max-w-4xl">
450
+ <div class="bg-white shadow overflow-hidden sm:rounded-lg">
451
+ <div class="px-4 py-5 sm:px-6">
452
+ <h1 class="text-2xl leading-6 font-medium text-gray-900">Project Report</h1>
453
+ <p class="mt-1 max-w-2xl text-sm text-gray-500">Detailed analysis and insights</p>
454
+ </div>
455
+ <div class="border-t border-gray-200">
456
+ <dl>
457
+ <div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
458
+ <dt class="text-sm font-medium text-gray-500">Repository Details</dt>
459
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.repository_details}</dd>
460
+ </div>
461
+
462
+ <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
463
+ <dt class="text-sm font-medium text-gray-500">Category</dt>
464
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{format_category(report.category)}</dd>
465
+ </div>
466
+
467
+ <div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
468
+ <dt class="text-sm font-medium text-gray-500">Language</dt>
469
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.language}</dd>
470
+ </div>
471
+
472
+ <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
473
+ <dt class="text-sm font-medium text-gray-500">Activity Metrics</dt>
474
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.activity_metrics}</dd>
475
+ </div>
476
+
477
+ <div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
478
+ <dt class="text-sm font-medium text-gray-500">Community Involvement</dt>
479
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.community_involvement}</dd>
480
+ </div>
481
+
482
+ <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
483
+ <dt class="text-sm font-medium text-gray-500">Development Practices</dt>
484
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.development_practices}</dd>
485
+ </div>
486
+
487
+ <div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
488
+ <dt class="text-sm font-medium text-gray-500">Skill Score</dt>
489
+ <dd class="sm:mt-0 sm:col-span-2">
490
+ <div class="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
491
+ <div class="bg-blue-600 h-2.5 rounded-full" style="width: #{report.skill_score * 10}%"></div>
492
+ </div>
493
+ </dd>
494
+ </div>
495
+
496
+ <div class="bg-white px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
497
+ <dt class="text-sm font-medium text-gray-500">Potential Score</dt>
498
+ <dd class="sm:mt-0 sm:col-span-2">
499
+ <div class="w-full bg-gray-200 rounded-full h-2.5 dark:bg-gray-700">
500
+ <div class="bg-green-600 h-2.5 rounded-full" style="width: #{report.potential_score * 10}%"></div>
501
+ </div>
502
+ </dd>
503
+ </div>
504
+
505
+ <div class="bg-gray-50 px-4 py-5 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
506
+ <dt class="text-sm font-medium text-gray-500">Conclusion</dt>
507
+ <dd class="mt-1 text-sm text-gray-900 sm:mt-0 sm:col-span-2">#{report.conclusion}</dd>
508
+ </div>
509
+ </dl>
510
+ </div>
511
+ </div>
512
+ </div>
513
+ </body>
514
+ </html>
515
+ """
516
+
517
+ send_event(ctx, origin, "replace", report_html)
518
+ {:reply, report_html, assign(ctx, html: report_html)}
519
+ end
520
+
521
+ def handle_call({:replace, report, origin}, _from, ctx) do
522
+ report_html =
523
+ case report do
524
+ nil ->
525
+ @empty_state
526
+
527
+ {:error, reason} ->
528
+ """
529
+ <!DOCTYPE html>
530
+ <html lang="en">
531
+ <head>
532
+ <meta charset="UTF-8">
533
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
534
+ <title>Error Page</title>
535
+ <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
536
+ </head>
537
+ <body class="bg-gray-900 text-white flex items-center justify-center h-screen">
538
+ <div class="text-center">
539
+ <div class="mb-4">
540
+ <svg xmlns="http://www.w3.org/2000/svg" class="h-20 w-20 mx-auto text-red-500" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
541
+ <path stroke-linecap="round" stroke-linejoin="round" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
542
+ </svg>
543
+ </div>
544
+ <h1 class="text-3xl font-semibold mb-2">Oops! Something went wrong.</h1>
545
+ <p class="text-lg text-gray-400">#{reason}</p>
546
+ </div>
547
+ </body>
548
+ </html>
549
+
550
+ """
551
+
552
+ :loading ->
553
+ """
554
+ <!DOCTYPE html>
555
+ <html lang="en">
556
+ <style>
557
+ .loader {
558
+ border: 16px solid #f3f3f3; /* Light grey */
559
+ border-top: 16px solid #3498db; /* Blue */
560
+ border-radius: 50%;
561
+ width: 120px;
562
+ height: 120px;
563
+ animation: spin 2s linear infinite;
564
+ }
565
+
566
+ @keyframes spin {
567
+ 0% { transform: rotate(0deg); }
568
+ 100% { transform: rotate(360deg); }
569
+ }
570
+ </style>
571
+ <head>
572
+ <meta charset="UTF-8">
573
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
574
+ <title>Report</title>
575
+ <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
576
+ </head>
577
+ <body class="bg-gray-100">
578
+ <div class="loader"></div>
579
+ </body>
580
+ """
581
+ end
582
+
583
+ send_event(ctx, origin, "replace", report_html)
584
+ {:reply, report_html, assign(ctx, html: report_html)}
585
+ end
586
+
587
+ asset "main.js" do
588
+ """
589
+ export function init(ctx, html) {
590
+ ctx.root.innerHTML = html;
591
+
592
+ ctx.handleEvent("replace", (html) => {
593
+ console.log(html);
594
+ ctx.root.innerHTML = html;
595
+ });
596
+ }
597
+ """
598
+ end
599
+ end
600
+ ```
601
+
602
+ ```elixir
603
+ live_report = LiveReport.new()
604
+
605
+ instructions =
606
+ Kino.Markdown.new("""
607
+ Welcome!
608
+
609
+ This demo showcases using LLMs to generate automated smart reports.
610
+
611
+ Here, we use the GitHub API + OpenAI to analyze your repository and give you a
612
+ downloadable report with insights about its suitability for open-source contributions
613
+ and an overall summary!
614
+
615
+ Get started by following the steps below:
616
+
617
+ 1. Enter your GitHub API Token. This should be a Classic Token with `repo` scope. [See Docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#personal-access-tokens-classic)
618
+ 1. Enter your OpenAI API Token. [See Docs](https://platform.openai.com/docs/quickstart/step-2-setup-your-api-key)
619
+ 1. Enter the name of the OpenAI model you would like to use [See Available Models](https://platform.openai.com/docs/models/models) (requires authentication)
620
+ * I suggest `gpt-4`, as it is likely that that the request will exceed the context window limit of `gpt-3.5-turbo`
621
+
622
+ If you liked this demo, consider giving a star to the wonderful libraries that helped power this app:
623
+
624
+ * [Livebook](https://github.com/livebook-dev/livebook) / [Kino](https://github.com/livebook-dev/kino/)
625
+ * [Instructor](https://github.com/thmsmlr/instructor_ex)
626
+ * [Req](https://github.com/wojtekmach/req)
627
+ * [OpenAI Elixir Wrapper](https://github.com/mgallo/openai.ex)
628
+ ---
629
+
630
+ You can also follow my work on [GitHub](https://github.com/acalejos)
631
+
632
+ You can read more long-form articles at [The Stack Canary](https://www.thestackcanary.com)
633
+
634
+ ![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/ac_alejos)
635
+ ---
636
+
637
+ """)
638
+
639
+ form =
640
+ Kino.Control.form(
641
+ [
642
+ github_token: Kino.Input.text("GitHub API Key"),
643
+ openai_token: Kino.Input.text("OpenAI API Key"),
644
+ model: Kino.Input.text("OpenAI Model"),
645
+ repo: Kino.Input.text("GitHub Repo (owner/repo)")
646
+ ],
647
+ submit: "Generate"
648
+ )
649
+
650
+ frame = Kino.Frame.new()
651
+
652
+ Kino.listen(form, fn
653
+ %{
654
+ data: %{repo: repo, github_token: gh_tok, openai_token: oai_tok, model: model},
655
+ origin: origin
656
+ } ->
657
+ LiveReport.loading(live_report, origin)
658
+
659
+ new_html =
660
+ cond do
661
+ repo == "" ->
662
+ LiveReport.replace(live_report, {:error, "Please specify a GitHub Repo"}, origin)
663
+
664
+ gh_tok == "" ->
665
+ LiveReport.replace(live_report, {:error, "Please specify a GitHub Token"}, origin)
666
+
667
+ oai_tok == "" ->
668
+ LiveReport.replace(live_report, {:error, "Please specify an OpenAI Token"}, origin)
669
+
670
+ model == "" ->
671
+ LiveReport.replace(live_report, {:error, "Please specify an OpenAI model"}, origin)
672
+
673
+ true ->
674
+ case repo |> ReportGenerator.generate_report(gh_tok, oai_tok, model) do
675
+ {:ok, report} ->
676
+ LiveReport.replace(live_report, report, origin)
677
+
678
+ {:error, reason} ->
679
+ cond do
680
+ String.contains?(reason, "invalid_api_key") ->
681
+ LiveReport.replace(live_report, {:error, "Invalid OpenAI API Key"}, origin)
682
+
683
+ String.contains?(reason, "invalid model ID") or
684
+ String.contains?(reason, "model_not_found") ->
685
+ LiveReport.replace(live_report, {:error, "Invalid OpenAI Model"}, origin)
686
+
687
+ true ->
688
+ LiveReport.replace(live_report, {:error, reason}, origin)
689
+ end
690
+ end
691
+ end
692
+
693
+ Kino.Frame.render(frame, Kino.Text.new(new_html, terminal: false))
694
+ end)
695
+
696
+ download =
697
+ Kino.Download.new(
698
+ fn ->
699
+ Kino.Frame.get_outputs(frame)
700
+ |> hd()
701
+ |> Map.get(:text)
702
+ end,
703
+ label: "Download Report",
704
+ filename: "report.html"
705
+ )
706
+
707
+ Kino.Layout.grid([instructions, form, live_report, download], columns: 1, gap: 4, boxed: true)
708
+ ```
709
+
710
+ <!-- livebook:{"offset":31074,"stamp":{"token":"XCP.onc6e6vcHY1ankirQw_JV6eLv2buba18ObiQngfKw-jQRGz99wvgiH_rRYsSTS5hOpf4k98j_4lCg9GY6ybuR8V7DvPj5PIeLI-HSkbmPlRHSspblkk_pLcdRPIbTr0Y6CGhoPyzov0","version":2}} -->
public-apps/welcome.livemd DELETED
@@ -1,46 +0,0 @@
1
- <!-- livebook:{"app_settings":{"access_type":"public","output_type":"rich","slug":"welcome"}} -->
2
-
3
- # Livebook <3 Hugging Face
4
-
5
- ```elixir
6
- Mix.install([
7
- {:kino, "~> 0.9"}
8
- ])
9
- ```
10
-
11
- ## Section
12
-
13
- This is the source of a deployed notebook.
14
- This notebook is static and simply renders the markdown content below.
15
-
16
- ```elixir
17
- Kino.Markdown.new("""
18
- Welcome to Livebook in Hugging Face!
19
-
20
- This is a deployed notebook, which is also a perfect place to teach you
21
- the ropes in using Livebook with Hugging Face.
22
-
23
- ## Getting started
24
-
25
- First off, if you want to run your own copy of Livebook,
26
- [check our tutorial](https://news.livebook.dev/livebook-inside-hugging-face-spaces-3LQaRi).
27
- Once you clone the space, remember to set `LIVEBOOK_PASSWORD` as
28
- an environment variable on your Space Settings page (a minimum of
29
- 12 digits is required).
30
-
31
- If you are new to Elixir and Livebook, [head out to the Learn page](/learn)
32
- (it requires a password), there you will find resources to get started
33
- with both.
34
-
35
- ## Deploying notebooks
36
-
37
- Livebook is fully collaborative and it enables you to deploy interactive
38
- and collaborative apps just as well. All of your deployable notebooks will
39
- be in the "public-apps" directory of your Spaces repository.
40
-
41
- To deploy your own notebook on Hugging Face, you must click the
42
- <i class="ri-livebook-deploy"></i> icon on the notebook sidebar, set a "Slug"
43
- for the notebook, mark it as public and then drop its `.livemd` file into
44
- the "public-apps" directory of your Spaces repo.
45
- """)
46
- ```