helloadhavan/github_issues huggingface dataset:
Repository: facebook/react
Pull request: Bump actions/checkout

<!--
  Thanks for submitting a pull request!
  We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory.

  Before submitting a pull request, please make sure the following is done:

  1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`.
  2. Run `yarn` in the repository root.
  3. If you've fixed a bug or added code that should be tested, add tests!
  4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
  5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`.
  6. If you need a debugger, run `yarn test --debug --watch TestName`, open `chrome://inspect`, and press "Inspect".
  7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`).
  8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

  Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html
-->

## Summary
GitHub is [planning to upgrade to Node 20](https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/). Versions prior to actions/checkout v3 use an outdated version of node, so we will upgrade to actions/checkout v4, where [Node 20 is the default](https://github.com/actions/checkout/releases/tag/v4.0.0).
<!--
 Explain the **motivation** for making this change. What existing problem does the pull request solve?
-->



Changed files:
filename: .github/workflows/commit_artifacts.yml
patch: @@ -11,7 +11,7 @@ jobs:
       www_branch_count: ${{ steps.check_branches.outputs.www_branch_count }}
       fbsource_branch_count: ${{ steps.check_branches.outputs.fbsource_branch_count }}
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
       - name: "Check branches"
         id: check_branches
         run: |
@@ -179,7 +179,7 @@ jobs:
     if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.www_branch_count == '0') || github.ref == 'refs/heads/meta-www' }}
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         with:
           ref: builds/facebook-www
       - name: Ensure clean directory
@@ -215,7 +215,7 @@ jobs:
     runs-on: ubuntu-latest
     if: ${{ (github.ref == 'refs/heads/main' && needs.download_artifacts.outputs.fbsource_branch_count == '0') || github.ref == 'refs/heads/meta-fbsource' }}
     steps:
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         with:
           ref: main
           repository: facebook/react-fbsource-import
Repository: vercel/next.js
Pull request: [turbopack] Fix a snapshot test

A recent output change in #82214 invalidated a new test added in #77616

A classic write-write race


Closes PACK-5168

Changed files:
filename: turbopack/crates/turbopack-tests/tests/snapshot/node/bun_protocol_external/output/[root-of-the-server]__e251cfe1._.js
patch: @@ -52,7 +52,7 @@ module.exports = mod;
 "use strict";
 
 // Test that Bun builtins are treated as external
-__turbopack_context__.s({});
+__turbopack_context__.s([]);
 var __TURBOPACK__imported__module__$5b$externals$5d2f$bun$3a$ffi__$5b$external$5d$__$28$bun$3a$ffi$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/bun:ffi [external] (bun:ffi, cjs)");
 var __TURBOPACK__imported__module__$5b$externals$5d2f$bun$3a$jsc__$5b$external$5d$__$28$bun$3a$jsc$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/bun:jsc [external] (bun:jsc, cjs)");
 var __TURBOPACK__imported__module__$5b$externals$5d2f$bun$3a$sqlite__$5b$external$5d$__$28$bun$3a$sqlite$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/bun:sqlite [external] (bun:sqlite, cjs)");
Repository: ollama/ollama
Pull request: fix typo


Changed files:
filename: api/types.go
patch: @@ -57,7 +57,7 @@ func (r *GenerateResponse) Summary() {
 	}
 
 	if r.EvalDuration > 0 {
-		fmt.Fprintf(os.Stderr, "eval duraiton:        %s\n", r.EvalDuration)
+		fmt.Fprintf(os.Stderr, "eval duration:        %s\n", r.EvalDuration)
 		fmt.Fprintf(os.Stderr, "eval rate:            %.2f tokens/s\n", float64(r.EvalCount)/r.EvalDuration.Seconds())
 	}
 }
Repository: nodejs/node
Pull request: doc: fix winget config path

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: BUILDING.md
patch: @@ -683,7 +683,7 @@ easily. These files will install the following
 To install Node.js prerequisites from Powershell Terminal:
 
 ```powershell
-winget configure .\configuration.dsc.yaml
+winget configure .\configurations\configuration.dsc.yaml
 ```
 
 Alternatively, you can use [Dev Home](https://learn.microsoft.com/en-us/windows/dev-home/)
Repository: ollama/ollama
Pull request: fix pull race

Fixes #75 

Changed files:
filename: server/models.go
patch: @@ -76,22 +76,10 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
 		return fmt.Errorf("failed to download model: %w", err)
 	}
 
-	// check if completed file exists
-	fi, err := os.Stat(model.FullName())
-	switch {
-	case errors.Is(err, os.ErrNotExist):
-		// noop, file doesn't exist so create it
-	case err != nil:
-		return fmt.Errorf("stat: %w", err)
-	default:
-		fn(fi.Size(), fi.Size())
-		return nil
-	}
-
 	var size int64
 
 	// completed file doesn't exist, check partial file
-	fi, err = os.Stat(model.TempFile())
+	fi, err := os.Stat(model.TempFile())
 	switch {
 	case errors.Is(err, os.ErrNotExist):
 		// noop, file doesn't exist so create it

filename: server/routes.go
patch: @@ -105,6 +105,24 @@ func pull(c *gin.Context) {
 		return
 	}
 
+	// check if completed file exists
+	fi, err := os.Stat(remote.FullName())
+	switch {
+	case errors.Is(err, os.ErrNotExist):
+		// noop, file doesn't exist so create it
+	case err != nil:
+		c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+		return
+	default:
+		c.JSON(http.StatusOK, api.PullProgress{
+			Total:     fi.Size(),
+			Completed: fi.Size(),
+			Percent:   100,
+		})
+
+		return
+	}
+
 	ch := make(chan any)
 	go stream(c, ch)
Repository: ggml-org/llama.cpp
Pull request: Fix messages payload sent to chat completions

Close #16385

Fixes messages payload to include only the currently active message branches in the chat completions request payload.

Changed files:
filename: tools/server/webui/src/lib/stores/chat.svelte.ts
patch: @@ -550,7 +550,6 @@ class ChatStore {
 				await this.updateConversationName(this.activeConversation.id, title);
 			}
 
-			const allMessages = await DatabaseStore.getConversationMessages(this.activeConversation.id);
 			const assistantMessage = await this.createAssistantMessage(userMessage.id);
 
 			if (!assistantMessage) {
@@ -560,15 +559,23 @@ class ChatStore {
 			this.activeMessages.push(assistantMessage);
 			// Don't update currNode until after streaming completes to maintain proper conversation path
 
-			await this.streamChatCompletion(allMessages, assistantMessage, undefined, (error: Error) => {
-				if (error.name === 'ContextError' && userMessage) {
-					const userMessageIndex = this.findMessageIndex(userMessage.id);
-					if (userMessageIndex !== -1) {
-						this.activeMessages.splice(userMessageIndex, 1);
-						DatabaseStore.deleteMessage(userMessage.id).catch(console.error);
+			const conversationContext = this.activeMessages.slice(0, -1);
+
+			await this.streamChatCompletion(
+				conversationContext,
+				assistantMessage,
+				undefined,
+				(error: Error) => {
+					if (error.name === 'ContextError' && userMessage) {
+						const userMessageIndex = this.findMessageIndex(userMessage.id);
+
+						if (userMessageIndex !== -1) {
+							this.activeMessages.splice(userMessageIndex, 1);
+							DatabaseStore.deleteMessage(userMessage.id).catch(console.error);
+						}
 					}
 				}
-			});
+			);
 		} catch (error) {
 			if (this.isAbortError(error)) {
 				this.isLoading = false;
@@ -810,7 +817,6 @@ class ChatStore {
 			this.currentResponse = '';
 
 			try {
-				const allMessages = await DatabaseStore.getConversationMessages(this.activeConversation.id);
 				const assistantMessage = await this.createAssistantMessage();
 
 				if (!assistantMessage) {
@@ -821,7 +827,9 @@ class ChatStore {
 				await DatabaseStore.updateCurrentNode(this.activeConversation.id, assistantMessage.id);
 				this.activeConversation.currNode = assistantMessage.id;
 
-				await this.streamChatCompletion(allMessages, assistantMessage);
+				const conversationContext = this.activeMessages.slice(0, -1);
+
+				await this.streamChatCompletion(conversationContext, assistantMessage);
 			} catch (regenerateError) {
 				console.error('Failed to regenerate response:', regenerateError);
 				this.isLoading = false;
Repository: electron/electron
Pull request: perf: avoid redundant map lookup in `WebFrameMain` constructor

Backport of #46238

See that PR for details.


Notes: none

Changed files:
filename: shell/browser/api/electron_api_web_frame_main.cc
patch: @@ -156,8 +156,8 @@ WebFrameMain::WebFrameMain(content::RenderFrameHost* rfh)
   if (!render_frame_detached_)
     GetFrameTreeNodeIdMap().emplace(frame_tree_node_id_, this);
 
-  DCHECK(!GetFrameTokenMap().contains(frame_token_));
-  GetFrameTokenMap().emplace(frame_token_, this);
+  const auto [_, inserted] = GetFrameTokenMap().emplace(frame_token_, this);
+  DCHECK(inserted);
 
   // WebFrameMain should only be created for active or unloading frames.
   DCHECK(GetLifecycleState(rfh) == LifecycleState::kActive ||
Repository: ollama/ollama
Pull request: fix eof error in generate

maybe related to #72 

Changed files:
filename: cmd/cmd.go
patch: @@ -59,7 +59,7 @@ func pull(model string) error {
 		&api.PullRequest{Model: model},
 		func(progress api.PullProgress) error {
 			if bar == nil {
-				if progress.Percent == 100 {
+				if progress.Percent >= 100 {
 					// already downloaded
 					return nil
 				}
@@ -73,10 +73,9 @@ func pull(model string) error {
 }
 
 func RunGenerate(_ *cobra.Command, args []string) error {
-	// join all args into a single prompt
-	prompt := strings.Join(args[1:], " ")
 	if len(args) > 1 {
-		return generate(args[0], prompt)
+		// join all args into a single prompt
+		return generate(args[0], strings.Join(args[1:], " "))
 	}
 
 	if term.IsTerminal(int(os.Stdin.Fd())) {

filename: llama/llama.go
patch: @@ -199,10 +199,10 @@ func (llm *llama) generate(tokens []C.llama_token, fn func(string)) error {
 
 		token, err := llm.sample(pastTokens, &opts)
 		switch {
-		case err != nil:
-			return err
 		case errors.Is(err, io.EOF):
 			return nil
+		case err != nil:
+			return err
 		}
 
 		fn(llm.detokenize(token))

filename: server/models.go
patch: @@ -119,25 +119,22 @@ func saveModel(model *Model, fn func(total, completed int64)) error {
 	}
 	defer out.Close()
 
-	totalSize, _ := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
+	remaining, _ := strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64)
+	completed := size
 
-	totalBytes := size
-	totalSize += size
+	total := remaining + completed
 
 	for {
-		n, err := io.CopyN(out, resp.Body, 8192)
-		if err != nil && !errors.Is(err, io.EOF) {
-			return err
+		fn(total, completed)
+		if completed >= total {
+			return os.Rename(model.TempFile(), model.FullName())
 		}
 
-		if n == 0 {
-			break
+		n , err := io.CopyN(out, resp.Body, 8192)
+		if err != nil && !errors.Is(err, io.EOF) {
+			return err
 		}
 
-		totalBytes += n
-		fn(totalSize, totalBytes)
+		completed += n
 	}
-
-	fn(totalSize, totalSize)
-	return os.Rename(model.TempFile(), model.FullName())
 }

filename: server/routes.go
patch: @@ -112,7 +112,7 @@ func pull(c *gin.Context) {
 		ch <- api.PullProgress{
 			Total:     total,
 			Completed: completed,
-			Percent:   float64(total) / float64(completed) * 100,
+			Percent:   float64(completed) / float64(total) * 100,
 		}
 	}
Repository: ggml-org/llama.cpp
Pull request: Fix mobile unwanted scrolling

*Make sure to read the [contributing guidelines](https://github.com/ggml-org/llama.cpp/blob/master/CONTRIBUTING.md) before submitting a PR*

Description

This patch introduces dynamic viewport height handling in the main Svelte WebUI layout.

Problem

Using Tailwind’s h-screen relies on the CSS visual viewport height, which often doesn’t match the actual available space in the browser. On mobile devices (iOS/Android), the browser’s address bar appearing/disappearing leads to layout jumps, empty gaps, or hidden content. The UI isn’t always filling the screen as expected.

Solution

Added a reactive viewportHeight state, updated on every window.resize.

On onMount, the value is initialized with window.innerHeight.

The root container’s height is conditionally set with an inline style:height={viewportHeight}px.

Event listeners are properly cleaned up on unmount.

This ensures the layout always matches the real viewport height instead of relying on 100vh/h-screen quirks.

Benefits

Mobile UX is fixed: no more ghost scrollbars or clipped areas when the browser chrome toggles.

No regressions on desktop: viewportHeight just tracks the window height.

Lightweight, clean solution with minimal code changes.

Changed files:
filename: tools/server/webui/src/routes/+layout.svelte
patch: @@ -25,6 +25,7 @@
 	let isNewChatMode = $derived(page.url.searchParams.get('new_chat') === 'true');
 	let showSidebarByDefault = $derived(activeMessages().length > 0 || isLoading());
 	let sidebarOpen = $state(false);
+	let innerHeight = $state<number | undefined>();
 	let chatSidebar:
 		| { activateSearchMode?: () => void; editActiveConversation?: () => void }
 		| undefined = $state();
@@ -140,8 +141,6 @@
 	});
 </script>
 
-<svelte:window onkeydown={handleKeydown} />
-
 <ModeWatcher />
 
 <Toaster richColors />
@@ -157,7 +156,7 @@
 />
 
 <Sidebar.Provider bind:open={sidebarOpen}>
-	<div class="flex h-screen w-full">
+	<div class="flex h-screen w-full" style:height="{innerHeight}px">
 		<Sidebar.Root class="h-full">
 			<ChatSidebar bind:this={chatSidebar} />
 		</Sidebar.Root>
@@ -174,3 +173,5 @@
 		</Sidebar.Inset>
 	</div>
 </Sidebar.Provider>
+
+<svelte:window onkeydown={handleKeydown} bind:innerHeight />
Repository: ollama/ollama
Pull request: take all args as one prompt

- parse all run arguments into one prompt
- do not echo prompt back on one-shot
- example of summarizing a document

```
$ ollama run nous-hermes "$(cat input.txt)", please summarize this story
The song "Summertime" by Will Smith is about the rapper's life before fame and how it changed when he became successful. The lyrics describe his experiences growing up in Philadelphia and then suddenly becoming rich and famous. The song is a coming-of-age story that describes the rapper's journey from poverty to stardom, and the impact of this change on his life.
```

Changed files:
filename: README.md
patch: @@ -48,6 +48,14 @@ Get a helping hand.
 ollama run orca "Write an email to my boss."
 ```
 
+### 🔎 Ask questions about documents
+
+Send the contents of a document and ask questions about it.
+
+```
+ollama run nous-hermes "$(cat input.txt)", please summarize this story
+```
+
 ### 📖 Storytelling
 
 Venture into the unknown.

filename: cmd/cmd.go
patch: @@ -64,8 +64,10 @@ func pull(model string) error {
 }
 
 func RunGenerate(_ *cobra.Command, args []string) error {
+	// join all args into a single prompt
+	prompt := strings.Join(args[1:], " ")
 	if len(args) > 1 {
-		return generateOneshot(args[0], args[1:]...)
+		return generate(args[0], prompt)
 	}
 
 	if term.IsTerminal(int(os.Stdin.Fd())) {
@@ -114,17 +116,6 @@ func generate(model, prompt string) error {
 	return nil
 }
 
-func generateOneshot(model string, prompts ...string) error {
-	for _, prompt := range prompts {
-		fmt.Printf(">>> %s\n", prompt)
-		if err := generate(model, prompt); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}
-
 func generateInteractive(model string) error {
 	fmt.Print(">>> ")
 	scanner := bufio.NewScanner(os.Stdin)
Repository: electron/electron
Pull request: build: fixup windows source cache for release

Backport of #46236

See that PR for details.


Notes: <!-- Please add a one-line description for app developers to read in the release notes, or 'none' if no notes relevant to app developers. Examples and help on special cases: https://github.com/electron/clerk/blob/main/README.md#examples -->none


Changed files:
filename: .github/actions/build-electron/action.yml
patch: @@ -185,7 +185,7 @@ runs:
       if: ${{ inputs.is-release == 'true' }}
       run: |
         cd src
-        e d gn gen out/ffmpeg --args="import(\"//electron/build/args/ffmpeg.gn\") use_remoteexec=true $GN_EXTRA_ARGS"
+        gn gen out/ffmpeg --args="import(\"//electron/build/args/ffmpeg.gn\") use_remoteexec=true $GN_EXTRA_ARGS"
         e build --target electron:electron_ffmpeg_zip -C ../../out/ffmpeg -j $NUMBER_OF_NINJA_PROCESSES
     - name: Generate Hunspell Dictionaries ${{ inputs.step-suffix }}
       shell: bash

filename: .github/actions/install-build-tools/action.yml
patch: @@ -19,3 +19,4 @@ runs:
         e d cipd.bat --version
         cp "C:\Python311\python.exe" "C:\Python311\python3.exe"
       fi
+      echo "$HOME/.electron_build_tools/third_party/depot_tools" >> $GITHUB_PATH

filename: .github/actions/restore-cache-azcopy/action.yml
patch: @@ -97,18 +97,28 @@ runs:
       $TEMP_DIR=New-Item -ItemType Directory -Path temp-cache
       $TEMP_DIR_PATH = $TEMP_DIR.FullName
       C:\ProgramData\Chocolatey\bin\7z.exe -y x $src_cache -o"$TEMP_DIR_PATH"
-      if (Test-Path "temp-cache\src") {
-        Write-Host "Relocating Cache"
-        Remove-Item -Recurse -Force src
-        Move-Item temp-cache\src src
 
-        Write-Host "Deleting zip file"
-        Remove-Item -Force $src_cache
-      }
-      if (-Not (Test-Path "src\third_party\blink")) {
-        Write-Host "Cache was not correctly restored - exiting"
-        exit 1
-      }
+  - name: Move Src Cache (Windows)
+    if: ${{ inputs.target-platform == 'win' }}
+    uses: nick-fields/retry@7152eba30c6575329ac0576536151aca5a72780e # v3.0.0
+    with:
+      timeout_minutes: 30
+      max_attempts: 3
+      retry_on: error
+      shell: powershell  
+      command: |
+        if (Test-Path "temp-cache\src") {
+          Write-Host "Relocating Cache"
+          Remove-Item -Recurse -Force src
+          Move-Item temp-cache\src src
+
+          Write-Host "Deleting zip file"
+          Remove-Item -Force $src_cache
+        }
+        if (-Not (Test-Path "src\third_party\blink")) {
+          Write-Host "Cache was not correctly restored - exiting"
+          exit 1
+        }
 
-      Write-Host "Wiping Electron Directory"
-      Remove-Item -Recurse -Force src\electron
\ No newline at end of file
+        Write-Host "Wiping Electron Directory"
+        Remove-Item -Recurse -Force src\electron
Repository: ollama/ollama
Pull request: Do not seg fault on client disconnect

This was nicer to fix on the revised `b2` branch, so this is a pull request into that simplified change

Changed files:
filename: llama/llama.go
patch: @@ -13,7 +13,7 @@ import (
 )
 
 type LLama struct {
-	ctx         *C.struct_llama_context
+	ctx *C.struct_llama_context
 }
 
 func New(modelpath string, mo ModelOptions) (*LLama, error) {
@@ -56,7 +56,7 @@ func sampleTokenGreedy(candidates []C.llama_token_data) C.int {
 	return max.id
 }
 
-func (l *LLama) Predict(prompt string, po PredictOptions, ch chan string) error {
+func (l *LLama) Predict(prompt string, po PredictOptions, ch chan string, stop chan struct{}) error {
 	toks := make([]C.llama_token, len(prompt))
 	toksPtr := (*C.llama_token)(unsafe.Pointer(&toks[0]))
 
@@ -92,19 +92,24 @@ func (l *LLama) Predict(prompt string, po PredictOptions, ch chan string) error
 		candidates := make([]C.llama_token_data, nVocab)
 		for i := range candidates {
 			candidates[i] = C.llama_token_data{
-				id: C.llama_token(i),
+				id:    C.llama_token(i),
 				logit: *(*C.float)(unsafe.Pointer(uintptr(unsafe.Pointer(logits)) + uintptr(i)*unsafe.Sizeof(*logits))),
-				p: C.float(0.0),
+				p:     C.float(0.0),
 			}
 		}
 
 		newTokenId = sampleTokenGreedy(candidates)
 
 		if newTokenId == C.llama_token_eos() {
-			break;
+			break
 		}
 
-		ch <- C.GoString(C.llama_token_to_str(l.ctx, newTokenId))
+		select {
+		case <-stop:
+			return nil
+		default:
+			ch <- C.GoString(C.llama_token_to_str(l.ctx, newTokenId))
+		}
 
 		toks = []C.llama_token{newTokenId}
 		toksPtr = (*C.llama_token)(unsafe.Pointer(&toks[0]))

filename: server/routes.go
patch: @@ -59,13 +59,6 @@ func generate(c *gin.Context) {
 	modelOpts := getModelOpts(req)
 	modelOpts.NGPULayers = 1 // hard-code this for now
 
-	model, err := llama.New(req.Model, modelOpts)
-	if err != nil {
-		fmt.Println("Loading the model failed:", err.Error())
-		return
-	}
-	defer model.Free()
-
 	templateNames := make([]string, 0, len(templates.Templates()))
 	for _, template := range templates.Templates() {
 		templateNames = append(templateNames, template.Name())
@@ -86,7 +79,25 @@ func generate(c *gin.Context) {
 
 	ch := make(chan string)
 	defer close(ch)
-	go model.Predict(req.Prompt, predictOpts, ch)
+	stop := make(chan struct{})
+	defer close(stop)
+
+	go func() {
+		model, err := llama.New(req.Model, modelOpts)
+		if err != nil {
+			fmt.Println("Loading the model failed:", err.Error())
+			return
+		}
+		defer model.Free()
+		if err := model.Predict(req.Prompt, predictOpts, ch, stop); err != nil {
+			if errors.Is(err, io.EOF) {
+				fmt.Println("Client disconnected:", err.Error())
+				return
+			}
+			fmt.Println("Error in prediction:", err.Error())
+			return
+		}
+	}()
 
 	c.Stream(func(w io.Writer) bool {
 		token, ok := <-ch