Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/pages/features/ai.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Flex, Layout } from "antd";67import AIAvatar from "@cocalc/frontend/components/ai-avatar";8import AnthropicAvatar from "@cocalc/frontend/components/anthropic-avatar";9import GoogleGeminiLogo from "@cocalc/frontend/components/google-gemini-avatar";10import MistralAvatar from "@cocalc/frontend/components/mistral-avatar";11import OllamaAvatar from "@cocalc/frontend/components/ollama-avatar";12import OpenAIAvatar from "@cocalc/frontend/components/openai-avatar";13import { DOC_AI } from "@cocalc/util/consts/ui";14import { COLORS } from "@cocalc/util/theme";15import Content from "components/landing/content";16import Footer from "components/landing/footer";17import Head from "components/landing/head";18import Header from "components/landing/header";19import Image from "components/landing/image";20import Info from "components/landing/info";21import LaTeX from "components/landing/latex";22import Pitch from "components/landing/pitch";23import SignIn from "components/landing/sign-in";24import { Paragraph, Text, Title } from "components/misc";25import A from "components/misc/A";26import { Customize } from "lib/customize";27import withCustomize from "lib/with-customize";28import AiLateXGenerate from "/public/features/ai-latex-generate.png";29import AiLaTeXHelpMeFix from "/public/features/ai-latex-help-me-fix.png";30import AILaTeXAnswer from "/public/features/ai-latex-maxwell-answer.png";31import AILLMQuery from "/public/features/ai-llm-cprogram-query.png";32import AILLMCprogramRun from "/public/features/ai-llm-cprogram-run.png";33import ChatGptInChatroom from "/public/features/chatgpt-fix-code.png";34import ChatGptGenerateCodeRun from "/public/features/chatgpt-generate-code-run.png";35import ChatGptGenerateCode from "/public/features/chatgpt-generate-code.png";36import ChatGptJupyterCell from "/public/features/chatgpt-jupyter-linear-regression-cell.png";37import ChatGptJupyterPrompt from "/public/features/chatgpt-jupyter-linear-regression-prompt.png";3839const title = `AI Assistant`;40const component = title;4142export default function AI({ customize }) {43const {44googleVertexaiEnabled,45openaiEnabled,46mistralEnabled,47anthropicEnabled,48ollamaEnabled,49} = customize;5051const iconTxtStyle = {52fontSize: "20px",53verticalAlign: "text-bottom",54};5556const codePrompt =57"Write a short C program, which iterates over all numbers from 0 to 100 and sums up those, which are divisible by 7!";5859return (60<Customize value={customize}>61<Head title={`${title} | Features | CoCalc`} />62<Layout>63<Header page="features" subPage="ai" />64<Layout.Content>65<Content66landing67startup={component}68body={<AIAvatar size={128} />}69title={title}70subtitleBelow={true}71subtitle={72<>73<div>74CoCalc integrates large language models including{" "}75<A href="https://openai.com/">OpenAI's ChatGPT</A>,{" "}76<A href="https://deepmind.google/technologies/gemini/">77Google's Gemini78</A>79,{" "}80<A href="https://www.anthropic.com/claude">81Anthropic's Claude82</A>83, and <A href="https://mistral.ai/">Mistral</A> as virtual84assistants. They generate human-like responses and code,85assist with programming, explain error messages, and86ultimately making it easier for you to get your work done.87</div>88</>89}90image={AILLMQuery}91alt={"AI Assistant in CoCalc"}92caption={"AI Assistant in CoCalc"}93/>9495<Pitch96col1={97<>98<Title level={2}>Help with coding</Title>99<Paragraph>100<li>Understand a vast array of programming languages.</li>101<li>Generate context-specific code based on your input.</li>102<li>103Interpret error messages, providing insightful suggestions.104</li>105<li>106Enhance code quality by modifying your provided code107snippets.108</li>109</Paragraph>110</>111}112col2={113<>114<Title level={2}>Virtual assistant</Title>115<Paragraph>116<li>117These language models, as virtual assistants, rectify bugs,118comprehend and write code across many programming languages119in a very convenient way.120</li>121<li>They are capable of appending documentation to code.</li>122<li>123They can even build upon existing code based on provided124directives.125</li>126</Paragraph>127</>128}129/>130131<Info.Heading132style={{ backgroundColor: COLORS.BS_GREEN_LL }}133description={134<>135<Paragraph style={{ marginTop: "20px" }}>136There are various places where an AI Assistant appears in137CoCalc, as illustrated below and{" "}138<A href={DOC_AI}>explained in the docs</A>.139</Paragraph>140<Paragraph>141CoCalc currently supports the following language models:142</Paragraph>143<Paragraph>144<Flex145style={{ margin: "20px" }}146justify="space-between"147align="center"148wrap="wrap"149>150{openaiEnabled ? (151<span style={{ margin: "10px", whiteSpace: "nowrap" }}>152<OpenAIAvatar size={32} />{" "}153<A154href="https://openai.com/chatgpt"155style={iconTxtStyle}156>157OpenAI's ChatGPT158</A>159</span>160) : undefined}161{googleVertexaiEnabled ? (162<span style={{ margin: "10px", whiteSpace: "nowrap" }}>163<GoogleGeminiLogo size={32} />{" "}164<A165href="https://deepmind.google/technologies/gemini/"166style={iconTxtStyle}167>168Google's Gemini169</A>170</span>171) : undefined}172{anthropicEnabled ? (173<span style={{ margin: "10px", whiteSpace: "nowrap" }}>174<AnthropicAvatar size={32} />{" "}175<A176href="https://www.anthropic.com/claude"177style={iconTxtStyle}178>179Anthropic's Claude180</A>181</span>182) : undefined}183{mistralEnabled ? (184<span style={{ margin: "10px", whiteSpace: "nowrap" }}>185<MistralAvatar size={32} />{" "}186<A href="https://mistral.ai/" style={iconTxtStyle}>187Mistral188</A>189</span>190) : undefined}191{ollamaEnabled ? (192<span style={{ margin: "10px", whiteSpace: "nowrap" }}>193<OllamaAvatar size={32} />{" "}194<A href="https://ollama.com/" style={iconTxtStyle}>195Ollama196</A>197</span>198) : undefined}199</Flex>200</Paragraph>201</>202}203>204AI language models in CoCalc205</Info.Heading>206207<ChatGPTFixError />208209<Info210title={"Mention AI models in any Chatroom in CoCalc"}211icon="comment"212image={ChatGptGenerateCode}213anchor="a-mention"214alt="ChatGPT generates code in a chatroom"215>216<Paragraph>217Here, a user learning <A href="https://pytorch.org/">PyTorch</A>{" "}218asks ChatGPT by{" "}219<A href={`${DOC_AI}#chatgpt-in-chat-rooms-and-side-chat`}>220mentioning221</A>{" "}222<Text code>@</Text> in a{" "}223<A href="https://doc.cocalc.com/chat.html#side-chat">Side Chat</A>224. The prompt is:225</Paragraph>226<Paragraph>227<blockquote>multiply two random matrices in pytorch</blockquote>228</Paragraph>229<Paragraph>230Sure enough, ChatGPT generates code that does exactly that. By231copying that simple example into your Jupyter Notebook, the user232can immediately run it and continue to play around with it.233</Paragraph>234<Paragraph>235<Image236src={ChatGptGenerateCodeRun}237alt="Running code snippet generated by ChatGPT"238/>239</Paragraph>240{googleVertexaiEnabled ? (241<Paragraph>242Note: Use @ also to talk to Google's Gemini model.243</Paragraph>244) : undefined}245</Info>246247<Info248narrow249title={"Generate Jupyter Cells"}250icon="jupyter"251anchor="a-jupyter"252alt="Generate Jupyter Cells"253image={ChatGptJupyterCell}254style={{ backgroundColor: COLORS.BLUE_LLLL }}255>256<Paragraph>257In a <A href="./jupyter-notebook">Jupyter Notebook</A>, you can258tell a language model to generate a cell for you. This is useful259if you want to explore a topic, but don't know where to start. In260the example on the left, we ask ChatGPT to generate a cell for us261about a linear regression for a stochastic process:262</Paragraph>263<Paragraph>264<Image265src={ChatGptJupyterPrompt}266alt="ChatGPT cell prompt in Jupyter Notebook"267/>268</Paragraph>269</Info>270271<Info272title={"Generating Code"}273icon="pen"274image={AILLMCprogramRun}275anchor="a-cpp"276alt="Gemini generates C++ code in a file"277narrow278caption={<blockquote>{codePrompt}</blockquote>}279below={280<Paragraph>281After the code is generated, we copy it into the282<Text code>c-program.cpp</Text> file as depicted. To compile and283run the C++ program, we use the <Text code>clang++</Text>{" "}284compiler provided in the{" "}285<A href="https://doc.cocalc.com/frame-editor.html">286Frame Editor's287</A>{" "}288<A href="/features/terminal">Terminal</A>.289</Paragraph>290}291>292<Paragraph>293ChatGPT or Gemini can also generate source code for you. In the294example displayed on the left, we first create an empty file named{" "}295<Text code>c-program.cpp</Text> in C++. Next, we open the AI296Assistant dialogue and prompt it to generate some code:297</Paragraph>298<Paragraph>299<Image src={AILLMQuery} alt={codePrompt} />300</Paragraph>301</Info>302303<Info304title={305<>306Help with <LaTeX />307</>308}309icon="question-circle"310anchor="a-latex"311alt="Help with LaTeX"312image={AiLateXGenerate}313style={{ backgroundColor: COLORS.BLUE_LLLL }}314below={315<>316<Paragraph>317On top of that, it can even assist you in{" "}318<Text strong>fixing LaTeX error messages</Text>. the "Help me319fix this…" button, and CoCalc will submit the error message,320some context, and a prompt for correction. This will provide321you with a useful indicator of the issue and potential322solutions.323</Paragraph>324<Paragraph style={{ textAlign: "center" }}>325<Image326src={AiLaTeXHelpMeFix}327alt="ChatGPT helps with LaTeX error messages"328/>329</Paragraph>330</>331}332>333<Paragraph>334Writing documents in the typesetting language{" "}335<A href="./latex-editor">LaTeX</A> can be challenging. In the336example on the left, we ask ChatGPT to generate the LaTeX formulas337for the Maxell equations. Sure enough, it answers with a short338explanation and a snippet of LaTeX code.339</Paragraph>340<Paragraph>341<Image342src={AILaTeXAnswer}343alt="ChatGPT generates LaTeX code for Maxwell equations"344/>345</Paragraph>346</Info>347348<SignIn startup={component} />349</Layout.Content>350<Footer />351</Layout>352</Customize>353);354}355356export async function getServerSideProps(context) {357return await withCustomize({ context });358}359360export function ChatGPTFixError({ embedded = false }: { embedded?: boolean }) {361const title = embedded ? "ChatGPT fixes code" : "Help fixing code";362363// a general intro about what this is, if this block is embeded on another page364function intro() {365if (!embedded) return null;366return (367<Paragraph>368Use the power of <A href="/features/ai">ChatGPT</A> to help fixing369errors or to generate code.370</Paragraph>371);372}373374return (375<Info376title={title}377icon="bug"378image={ChatGptInChatroom}379anchor="a-chatgpt-notebook"380alt="ChatGPT explains an error message and fixes code"381wide382>383{intro()}384<Paragraph>385In this example, a code cell in a{" "}386<A href="/features/jupyter-notebook">Jupyter Notebook</A> returned an387error. Clicking the botton to explain the error message creates a388message addressed to ChatGPT, which asks for help and to fix the code.389</Paragraph>390<Paragraph>391With enough context – the few lines of input code and the lines in the392stacktrace – it will attempt to fix the code for you. The fix might not393be perfect, but it can be a good starting point.394</Paragraph>395</Info>396);397}398399400